diff --git a/README.md b/README.md index 1e1d582..7f67602 100755 --- a/README.md +++ b/README.md @@ -1,43 +1,29 @@ -# HODClient Library for Android. V1.0 +# HavenOndemand Library for Android. V2.1 ---- ## Overview -HODClient library for Android is a lightweight Java based API, which helps you easily integrate your Android app with HP Haven OnDemand Services. +HavenOndemand library for Android is a lightweight Java based API, which helps you easily access over 60 APIs from HPE HavenOnDemand platform. + +The library contains 2 packages: + +HODClient package for sending HTTP GET/POST requests to HavenOnDemand APIs. + +HODResponseParser package for parsing JSON responses from HavenOnDemand APIs. HODClient library requires a minimum Android API level 10. ---- -## Integrate HODClient into an Android project -1. Download the HODClient library project for Android. -2. Create a new or open an existing Android project -3. Select the app main folder and click on the File menu then choose Import Module option. ->![](/images/importlibrary1.jpg) -4. Browse to HODClient folder and click OK. The HODClient folder should be created into your project. -![](/images/importlibrary2.jpg) -5. Open the main project build.gradle and add packaging options and the dependency as follows: - - android { - - packagingOptions { - exclude 'META-INF/DEPENDENCIES' - exclude 'META-INF/NOTICE' - exclude 'META-INF/LICENSE' - exclude 'META-INF/LICENSE.txt' - exclude 'META-INF/NOTICE.txt' - exclude 'META-INF/ASL2.0' - } - - } - - dependencies { +## Integrate HavenOnDemand into an Android project +Open your app build.gradle and add the dependency as follows: - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':hodclient') - + dependencies { + // add hodclient and hodresponseparser dependencies + compile 'com.havenondemand:hodclient:2.1' + compile 'com.havenondemand:hodresponseparser:2.1' } ---- -## API References +## HODClient API References **Constructor** HODClient(String apiKey, IHODClientCallback callback) @@ -61,10 +47,10 @@ HODClient library requires a minimum Android API level 10. { HODClient hodClient = new HODClient("your-api-key", this); - @Override + @Override public void requestCompletedWithJobID(String response){ } - @Override + @Override public void requestCompletedWithContent(String response){ } @Override @@ -87,13 +73,20 @@ HODClient library requires a minimum Android API level 10. >Note: ->In the case of a parameter type is an array<>, the key must be defined as "arrays" and the value must be a Map\ object with the key is the parameter name and the values separated by commas ",". +>In the case of a parameter type is an array<>, the value must be defined as a List\ object. >E.g.: ## - Map entity_array = new HashMap(); - entity_array.put("entity_type", "people_eng,places_eng"); - params.put("arrays", entity_array); - + Map params = new HashMap(); + List urls = new ArrayList(); + urls.add("http://www.cnn.com"); + urls.add("http://www.bbc.com"); + params.put("url", urls); + params.put("unique_entities", "true"); + List entities = new ArrayList(); + entities.add("people_eng"); + entities.add("places_eng"); + params.put("entity_type", entities); + * hodApp: a string to identify a Haven OnDemand API. E.g. "extractentities". Current supported apps are listed in the HODApps class. * mode [REQ_MODE.SYNC | REQ_MODE.ASYNC]: specifies API call as Asynchronous or Synchronous. @@ -110,9 +103,10 @@ HODClient library requires a minimum Android API level 10. String hodApp = HODApps.ENTITY_EXTRACTION; Map params = new HashMap(); params.put("url", "http://www.cnn.com"); - Map entity_array = new HashMap(); - entity_array.put("entity_type", "people_eng,places_eng"); - params.put("arrays", entity_array); + List entities = new ArrayList(); + entities.add("people_eng"); + entities.add("places_eng"); + params.put("entity_type", entities); hodClient.GetRequest(params, hodApp, HODClient.REQ_MODE.SYNC); ---- @@ -130,12 +124,19 @@ HODClient library requires a minimum Android API level 10. >Note: ->In the case of a parameter type is an array<>, the key must be defined as "arrays" and the value must be a Map\ object with the key is the parameter name and the values separated by commas ",". -E.g.: +>In the case of a parameter type is an array<>, the value must be defined as a List\ object. +>E.g.: ## - Map entity_array = new HashMap(); - entity_array.put("entity_type", "people_eng,places_eng"); - params.put("arrays", entity_array); + Map params = new HashMap(); + List urls = new ArrayList(); + urls.add("http://www.cnn.com"); + urls.add("http://www.bbc.com"); + params.put("url", urls); + params.put("unique_entities", "true"); + List entities = new ArrayList(); + entities.add("people_eng"); + entities.add("places_eng"); + params.put("entity_type", entities); * hodApp: a string to identify a Haven OnDemand API. E.g. "ocrdocument". Current supported apps are listed in the IODApps class. * mode [REQ_MODE.SYNC | REQ_MODE.ASYNC]: specifies API call as Asynchronous or Synchronous. @@ -189,6 +190,39 @@ E.g.: } catch (Exception ex) { } } +---- +**Function GetJobStatus** + + void GetJobStatus(String jobID) + +*Description:* + +* Sends a request to Haven OnDemand to retrieve status of a job identified by a job ID. If the job is completed, the response will be the result of that job. Otherwise, the response will contain the current status of the job. + +*Parameter:* + +* jobID: the job ID returned from a Haven OnDemand API upon an asynchronous call. + +*Response:* + +* Response will be returned via the requestCompletedWithContent(String response) + +*Example code:* +## + // Parse a JSON string contained a jobID and call the function to get the actual content from Haven OnDemand server + + @Override + public void requestCompletedWithJobID(String response) + { + try { + JSONObject mainObject = new JSONObject(response); + if (!mainObject.isNull("jobID")) { + jobID = mainObject.getString("jobID"); + hodClient.GetJobStatus(jobID); + } + } catch (Exception ex) { } + } + ---- ## API callback functions In your class, you will need to inherit the IHODClientCallback interface and implement callback functions to receive responses from the server @@ -214,7 +248,7 @@ When you call the GetRequest() or PostRequest() with the ASYNC mode, the respons } # -When you call the GetRequest() or PostRequest() with the SYNC mode or call the GetJobReslt() function, the response will be returned to this callback function. The response is a JSON string containing the actual result of the service. +When you call the GetRequest() or PostRequest() with the SYNC mode or call the GetJobResult() or GwtJobStatus() function, the response will be returned to this callback function. The response is a JSON string containing the actual result of the service. @Override public void requestCompletedWithContent(String response) @@ -231,6 +265,235 @@ If there is an error occurred, the error message will be returned to this callba } ---- +## HODResponseParser API References +**Constructor** + + HODResponseParser() + +*Description:* + +* Constructor. Creates and initializes an HODResponseParser object. + +*Parameters:* + +* None + +*Example code:* +## + + import hod.response.parser.HODErrorCode; + import hod.response.parser.HODErrorObject; + import hod.response.parser.HODResponseParser; + + public class MyActivity extends Activity + { + HODResponseParser hodParser = new HODResponseParser(); + + } + +---- +**Function ParseJobID** + + String ParseJobID(String response) + +*Description:* + +* Parses a jobID from a json string returned from an asynchronous API call. + +*Parameters:* + +* response: a json string returned from an asynchronous API call. + +*Return value:* + +* The jobID or an empty string if not found. + +*Example code:* +## + // Parse the jobID from within HODClient callback function + void requestCompletedWithJobID(string response) + { + String jobID = hodParser.ParseJobID(response); + if (jobID != "") + hodClient.GetJobResult(jobID); + } + +---- +**Function ParseSpeechRecognitionResponse** + + SpeechRecognitionResponse ParseSpeechRecognitionResponse(String jsonStr) + +*Description:* + +* Parses a json response from Haven OnDemand Speech Recognition API and returns a SpeechRegconitionResponse object. + +> Note: See the full list of standard parser functions from the Standard response parser functions section at the end of this document. + +*Parameters:* + +* jsonStr: a json string returned from a synchronous API call or from the GetJobResult() or GetJobStatus() function. + +*Return value:* + +* An object containing API's response values. If there is an error or if the job is not completed (callback from a GetJobStatus call), the returned object is null and the error or job status can be accessed by calling the GetLastError() function. + +*Example code:* +## + // Parse the Sentiment Analysis response from within HODClient callback function + void requestCompletedWithContent(string response) + { + SentimentAnalysisResponse resp = hodParser.ParseSentimentAnalysisResponse(response); + + if (resp != null) { + String positive = ""; + for (SentimentAnalysisResponse.Entity ent : resp.positive) { + if (ent.original_text != null) + positive += "Statement: " + ent.original_text + "\n"; + if (ent.sentiment != null) + positive += "Sentiment: " + ent.sentiment + "\n"; + if (ent.topic != null) + positive += "Topic: " + ent.topic + "\n"; + if (ent.score != null) + positive += "Score: " + ent.score.toString() + "\n"; + } + String negative = ""; + for (SentimentAnalysisResponse.Entity ent : resp.negative) { + if (ent.original_text != null) + negative += "Statement: " + ent.original_text + "\n"; + if (ent.sentiment != null) + negative += "Sentiment: " + ent.sentiment + "\n"; + if (ent.topic != null) + negative += "Topic: " + ent.topic + "\n"; + if (ent.score != null) + negative += "Score: " + ent.score.toString() + "\n"; + } + String sentiment = positive; + sentiment += negative; + sentiment += "Aggregate: \n" + resp.aggregate.sentiment + "\n"; + sentiment += resp.aggregate.score + "\n---"; + //print sentiment result + } else { // check status or handle error + List errors = hodParser.GetLastError(); + String errorMsg = ""; + for (HODErrorObject err: errors) { + if (err.error == HODErrorCode.QUEUED) { + // sleep for a few seconds then check the job status again + hodClient.GetJobStatus(err.jobID); + return; + } else if (err.error == HODErrorCode.IN_PROGRESS) { + // sleep for for a while then check the job status again + hodClient.GetJobStatus(err.jobID); + return; + } else { + errorMsg += String.format("Error code: %d\nError Reason: %s\n", err.error, err.reason); + if (err.detail != null) + errorMsg += "Error detail: " + err.detail + "\n"; + } + // print error message. + } + } + } +---- +**Function ParseCustomResponse** + + Object ParseCustomResponse(Class T, String jsonStr) + +*Description:* + +* Parses a json string and returns a custom object type based on the T class. + +*Parameters:* + +* \: a custom class object. +* jsonStr: a json string returned from a synchronous API call or from the GetJobResult() or GetJobStatus() function. + +*Return value:* + +* An object containing API's response values. If there is an error or if the job is not completed (callback from a GetJobStatus call), the returned object is null and the error or job status can be accessed by calling the GetLastError() function. + +*Example code:* +## + // Parse the Query Text Index response from within HODClient callback function + public class MyTextIndexResponse { + public List documents; + public class Document { + public String reference; + public String index; + public List store_name; + public List operation_time; + public List store_location; + public List contact_number; + public List product_category; + } + } + void requestCompletedWithContent(string response) + { + MyTextIndexResponse resp = (MyTextIndexResponse) hodParser.ParseCustomResponse(MyTextIndexResponse.class, response); + if (resp != null) { + for (MyTextIndexResponse.Document doc : resp.documents) { + // access document field ... + // e.g. doc.reference + } + } else { // check status or handle error + List errors = parser.GetLastError(); + String errorMsg = ""; + for (HODErrorObject err: errors) { + if (err.error == HODErrorCode.QUEUED) { + // sleep for a few seconds then check the job status again + hodClient.GetJobStatus(err.jobID); + return; + } else if (err.error == HODErrorCode.IN_PROGRESS) { + // sleep for for a while then check the job status again + hodClient.GetJobStatus(err.jobID); + return; + } else { + errorMsg += String.format("Error code: %d\nError Reason: %s\n", err.error, err.reason); + if (err.detail != null) + errorMsg += "Error detail: " + err.detail + "\n"; + } + // print error message. + } + } + } +---- +**Function GetLastError** + + List GetLastError() + +*Description:* + +* Get the latest error(s) if any happened during parsing the json string or HOD error returned from HOD server. > Note: The job "queued" or "in progress" status is also considered as an error situation. See the example below for how to detect and handle error status. + +*Parameters:* + +* None. + +*Return value:* + +* An list object contains HODErrorObject + +*Example code:* + +``` +List errors = parser.GetLastError(); +String errorMsg = ""; +for (HODErrorObject err : errors) { + if (err.error == HODErrorCode.QUEUED) { + hodClient.GetJobStatus(err.jobID); + return; + } else if (err.error == HODErrorCode.IN_PROGRESS) { + hodClient.GetJobStatus(err.jobID); + return; + } else { + errorMsg += String.format("Error code: %d\nError Reason: %s\n", err.error, err.reason); + if (err.detail != null) + errorMsg += "Error detail: " + err.detail + "\n"; + } + // print errorMsg +} +``` +---- + ## Demo code 1: **Call the Entity Extraction API to extract people and places from cnn.com website with a synchronous GET request** @@ -238,61 +501,87 @@ If there is an error occurred, the error message will be returned to this callba import com.hod.api.hodclient.IHODClientCallback; import com.hod.api.hodclient.HODApps; import com.hod.api.hodclient.HODClient; + import hod.response.parser.HODErrorCode; + import hod.response.parser.HODErrorObject; + import hod.response.parser.HODResponseParser; public class MyActivity extends Activity implements IHODClientCallback { HODClient hodClient; - + HODResponseParser hodParser; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); hodClient = new HODClient("your-apikey", this); + hodParser = new HODResponseParser(); useHODClient(); } private void useHODClient() { String hodApp = HODApps.ENTITY_EXTRACTION; - Map params = new HashMap(); - - Map arrays = new HashMap(); - arrays.put("entity_type", "people_eng,places_eng"); - params.put("url", "http://www.cnn.com"); - params.put("arrays", arrays); + List entities = new ArrayList(); + entities.add("people_eng"); + entities.add("places_eng"); + params.put("entity_type", entities); params.put("unique_entities", "true"); - + hodClient.GetRequest(params, hodApp, HODClient.REQ_MODE.SYNC); } + // define a custom response class + public class EntityExtractionResponse { + public List entities; + + public class AdditionalInformation + { + public List person_profession; + public String person_date_of_birth; + public String wikipedia_eng; + public Long place_population; + public String place_country_code; + public Double place_elevation; + } + public class Entity + { + public String normalized_text; + public String type; + public AdditionalInformation additional_information; + } + } + // implement callback functions @Override public void requestCompletedWithContent(String response) { - try { - JSONObject mainObject = new JSONObject(response); - JSONArray entitiesArray = mainObject.getJSONArray("entities"); - int count = entitiesArray.length(); - int i = 0; - String people = ""; - String places = ""; - - if (count > 0) { - for (i = 0; i < count; i++) { - JSONObject entity = entitiesArray.getJSONObject(i); - String type = entity.getString("type"); - if (type.equals("places_eng")) { - places += entity.getString("normalized_text") + "\n"; - // parse any other interested information about a place - } else if (type.equals("people_eng")) { - people += entity.getString("normalized_text"); - // parse any other interested information about a place - } + EntityExtractionResponse resp = (EntityExtractionResponse) hodParser.ParseCustomResponse(EntityExtractionResponse.class, response); + if (resp != null) { + String values = ""; + for (EntityExtractionResponse.Entity ent : resp.entities) { + values += ent.type + "\n"; + values += ent.normalized_text + "\n"; + if (ent.type.equals("places_eng")) { + values += ent.additional_information.place_country_code + "\n"; + values += ent.additional_information.place_elevation + "\n"; + values += ent.additional_information.place_population + "\n"; + } else if (ent.type.equals("people_eng")) { + values += ent.additional_information.person_date_of_birth + "\n"; + values += ent.additional_information.person_profession + "\n"; + values += ent.additional_information.wikipedia_eng + "\n"; } } - } catch (Exception ex) { - // handle exception + // print the values + } else { + List errors = parser.GetLastError(); + String errorMsg = ""; + for (HODErrorObject err : errors) { + errorMsg += String.format("Error code: %d\nError Reason: %s\n", err.error, err.reason); + if (err.detail != null) + errorMsg += "Error detail: " + err.detail + "\n"; + // handle error message + } } } @@ -311,23 +600,28 @@ If there is an error occurred, the error message will be returned to this callba import com.hod.api.hodclient.IHODClientCallback; import com.hod.api.hodclient.HODApps; import com.hod.api.hodclient.HODClient; + import hod.response.parser.HODErrorCode; + import hod.response.parser.HODErrorObject; + import hod.response.parser.HODResponseParser; + import hod.response.parser.OCRDocumentResponse; public class MyActivity extends Activity implements IHODClientCallback { HODClient hodClient; - + HODResponseParser hodParser; + String hodApp = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); hodClient = new HODClient("your-apikey", this); - + hodParser = new HODResponseParser(); useHODClient(); } private void useHODClient() { - String hodApp = HODApps.OCR_DOCUMENT; + hodApp = HODApps.OCR_DOCUMENT; Map params = new HashMap(); params.put("file", "path/and/filename"); @@ -344,43 +638,40 @@ If there is an error occurred, the error message will be returned to this callba **************************************************************************************/ @Override public void requestCompletedWithJobID(String response) { - try { - JSONObject mainObject = new JSONObject(response); - if (!mainObject.isNull("jobID")) { - jobID = mainObject.getString("jobID"); - hodClient.GetJobResult(jobID); - } - } catch (Exception ex) { - ;//HandleException(response); - } + String jobID = parser.ParseJobID(response); + if (jobID.length() > 0) + hodClient.GetJobStatus(jobID); } @Override public void requestCompletedWithContent(String response) { - try { - JSONObject mainObject = new JSONObject(response); - JSONArray textBlockArray = mainObject.getJSONArray("actions"); - int count = textBlockArray.length(); - String recognizedText = ""; - if (count > 0) { - for (int i = 0; i < count; i++) { - JSONObject actions = textBlockArray.getJSONObject(i); - JSONObject result = actions.getJSONObject("result"); - if (!result.isNull("text_block")) { - JSONArray textArray = result.getJSONArray("text_block"); - count = textArray.length(); - if (count > 0) { - for (int n = 0; n < count; n++) { - JSONObject texts = textArray.getJSONObject(n); - recognizedText += texts.getString("text"); - } - } - } + OCRDocumentResponse resp = hodParser.ParseOCRDocumentResponse(response); + if (resp != null) { + String text = ""; + for (OCRDocumentResponse.TextBlock block : resp.text_block) { + text += block.text + "\n"; + } + // print recognized text. + } else { + List errors = parser.GetLastError(); + String errorMsg = ""; + for (HODErrorObject err: errors) { + if (err.error == HODErrorCode.QUEUED) { + // sleep for a few seconds then check the job status again + hodClient.GetJobStatus(err.jobID); + return; + } else if (err.error == HODErrorCode.IN_PROGRESS) { + // sleep for for a while then check the job status again + hodClient.GetJobStatus(err.jobID); + return; + } else { + errorMsg += String.format("Error code: %d\nError Reason: %s\n", err.error, err.reason); + if (err.detail != null) + errorMsg += "Error detail: " + err.detail + "\n"; } + // print error message. } - } catch (Exception ex) { - // handle exception - } + } } @Override @@ -388,8 +679,109 @@ If there is an error occurred, the error message will be returned to this callba // handle error if any } } - +--- +## Standard response parser functions +``` +ParseSpeechRecognitionResponse(String jsonStr) +ParseCancelConnectorScheduleResponse(String jsonStr) +ParseConnectorHistoryResponse(String jsonStr) +ParseConnectorStatusResponse(String jsonStr) +ParseCreateConnectorResponse(String jsonStr) +ParseDeleteConnectorResponse(String jsonStr) +ParseRetrieveConnectorConfigurationFileResponse(String jsonStr) +ParseRetrieveConnectorConfigurationAttrResponse(String jsonStr) +ParseStartConnectorResponse(String jsonStr) +ParseStopConnectorResponse(String jsonStr) +ParseUpdateConnectorResponse(String jsonStr) +ParseExpandContainerResponse(String jsonStr) +ParseStoreObjectResponse(String jsonStr) +ParseViewDocumentResponse(String jsonStr) +ParseGetCommonNeighborsResponse(String jsonStr) +ParseGetNeighborsResponse(String jsonStr) +ParseGetNodesResponse(String jsonStr) +ParseGetShortestPathResponse(String jsonStr) +ParseGetSubgraphResponse(String jsonStr) +ParseSuggestLinksResponse(String jsonStr) +ParseSummarizeGraphResponse(String jsonStr) +ParseOCRDocumentResponse(String jsonStr) +ParseRecognizeBarcodesResponse(String jsonStr) +ParseRecognizeImagesResponse(String jsonStr) +ParseDetectFacesResponse(String jsonStr) +ParsePredictResponse(String jsonStr) +ParseRecommendResponse(String jsonStr) +ParseTrainPredictorResponse(String jsonStr) +ParseCreateQueryProfileResponse(String jsonStr) +ParseDeleteQueryProfileResponse(String jsonStr) +ParseRetrieveQueryProfileResponse(String jsonStr) +ParseUpdateQueryProfileResponse(String jsonStr) +ParseFindRelatedConceptsResponse(String jsonStr) +ParseAutoCompleteResponse(String jsonStr) +ParseExtractConceptsResponse(String jsonStr) +ParseExpandTermsResponse(String jsonStr) +ParseHighlightTextResponse(String jsonStr) +ParseIdentifyLanguageResponse(String jsonStr) +ParseTokenizeTextResponse(String jsonStr) +ParseSentimentAnalysisResponse(String jsonStr) +ParseAddToTextIndexResponse(String jsonStr) +ParseCreateTextIndexResponse(String jsonStr) +ParseDeleteTextIndexResponse(String jsonStr) +ParseDeleteFromTextIndexResponse(String jsonStr) +ParseIndexStatusResponse(String jsonStr) +ParseListResourcesResponse(String jsonStr) +ParseRestoreTextIndexResponse(String jsonStr) +``` ---- +## Supported standard response classes +``` +RecognizeSpeechResponse +CancelConnectorResponse +ConnectorHistoryResponse +ConnectorStatusResponse +CreateConnectorResponse +DeleteConnectorResponse +RetrieveConnectorConfigurationAttributeResponse +RetrieveConnectorConfigurationFileResponse +StartConnectorResponse +StopConnectorResponse +UpdateConnectorResponse +ExpandContainerResponse +StoreObjectResponse +ViewDocumentResponse +GetCommonNeighborsResponse +GetNeighborsResponse +GetNodesResponse +GetShortestPathResponse +GetSubgraphResponse +SuggestLinksResponse +SummarizeGraphResponse +OCRDocumentResponse +BarcodeRecognitionResponse +FaceDetectionResponse +ImageRecognitionResponse +PredictResponse +RecommendResponse +TrainPredictionResponse +CreateQueryProfileResponse +DeleteQueryProfileResponse +RetrieveQueryProfileResponse +UpdateQueryProfileResponse +FindRelatedConceptsResponse +AutoCompleteResponse +ConceptExtractionResponse +ExpandTermsResponse +HighlightTextResponse +LanguageIdentificationResponse +SentimentAnalysisResponse +TextTokenizationResponse +AddToTextIndexResponse +CreateTextIndexResponse +DeleteTextIndexResponse +DeleteFromTextIndexResponse +IndexStatusResponse +ListResourcesResponse +RestoreTextIndexResponse +``` +--- ## License Licensed under the MIT License. diff --git a/hodclient/build.gradle b/hodclient/build.gradle index 779f847..1449e2f 100755 --- a/hodclient/build.gradle +++ b/hodclient/build.gradle @@ -1,4 +1,27 @@ apply plugin: 'com.android.library' +ext { + bintrayRepo = 'maven' + bintrayName = 'havenondemand' + + publishedGroupId = 'com.havenondemand' + libraryName = 'HODClient' + artifact = 'hodclient' + + libraryDescription = 'A wrapper for easy access to over 60 APIs from HPE HavenOnDemand platform on Android' + + siteUrl = 'https://www.havenondemand.com' + gitUrl = 'https://github.com/HPE-Haven-OnDemand/havenondemand-android.git' + + libraryVersion = '2.1' + + developerId = 'PV' + developerName = 'Phong Vu' + developerEmail = 'phong.vu@hpe.com' + + licenseName = 'MIT license' + licenseUrl = '' + allLicenses = ["MIT"] +} android { compileSdkVersion 20 @@ -7,8 +30,8 @@ android { defaultConfig { minSdkVersion 10 targetSdkVersion 20 - versionCode 1 - versionName "1.0" + versionCode 3 + versionName "2.1" } buildTypes { release { @@ -16,6 +39,14 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + packagingOptions { + exclude 'META-INF/DEPENDENCIES' + exclude 'META-INF/NOTICE' + exclude 'META-INF/LICENSE' + exclude 'META-INF/LICENSE.txt' + exclude 'META-INF/NOTICE.txt' + exclude 'META-INF/ASL2.0' + } } dependencies { @@ -23,3 +54,6 @@ dependencies { compile files('httpcore-4.3.2.jar') compile files('httpcore-4.3.2.jar') } + +apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' +apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' \ No newline at end of file diff --git a/hodclient/hodclient.iml b/hodclient/hodclient.iml index bdd16b4..3c3bab7 100644 --- a/hodclient/hodclient.iml +++ b/hodclient/hodclient.iml @@ -1,5 +1,5 @@ - + @@ -65,6 +65,7 @@ + @@ -84,7 +85,9 @@ + + diff --git a/hodclient/src/main/java/hod/api/hodclient/HODApps.java b/hodclient/src/main/java/hod/api/hodclient/HODApps.java index 00b0164..e769c79 100755 --- a/hodclient/src/main/java/hod/api/hodclient/HODApps.java +++ b/hodclient/src/main/java/hod/api/hodclient/HODApps.java @@ -34,6 +34,9 @@ public class HODApps { public final static String SUGGEST_LINKS = "suggestlinks"; public final static String SUMMARIZE_GRAPH = "summarizegraph"; + public final static String ANOMALY_DETECTION = "anomalydetection"; + public final static String TREND_ANALYSIS = "trendanalysis"; + public final static String CREATE_CLASSIFICATION_OBJECTS = "createclassificationobjects"; public final static String CREATE_POLICY_OBJECTS = "createpolicyobjects"; public final static String DELETE_CLASSIFICATION_OBJECTS = "deleteclassificationobjects"; @@ -59,6 +62,7 @@ public class HODApps { public final static String QUERY_TEXT_INDEX = "querytextindex"; public final static String RETRIEVE_INDEX_FIELDS = "retrieveindexfields"; + public final static String AUTO_COMPLETE = "autocomplete"; public final static String CLASSIFY_DOCUMENT = "classifydocument"; public final static String EXTRACT_CONCEPTS = "extractconcepts"; public final static String CATEGORIZE_DOCUMENT = "categorizedocument"; diff --git a/hodclient/src/main/java/hod/api/hodclient/HODClient.java b/hodclient/src/main/java/hod/api/hodclient/HODClient.java index 695c07d..4912752 100755 --- a/hodclient/src/main/java/hod/api/hodclient/HODClient.java +++ b/hodclient/src/main/java/hod/api/hodclient/HODClient.java @@ -5,6 +5,7 @@ */ import android.net.Uri; import android.os.AsyncTask; +import android.util.Log; import android.webkit.MimeTypeMap; import org.apache.http.Consts; @@ -24,6 +25,7 @@ import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HTTP; import java.io.ByteArrayOutputStream; import java.io.File; @@ -32,11 +34,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Map; -/** - * Created by Paco on 8/27/2015. - */ public class HODClient { public HODApps hodApp; @@ -44,6 +44,7 @@ public enum REQ_MODE {SYNC, ASYNC }; private String apiKey = ""; private String hodBase = "https://api.havenondemand.com/1/api/"; private String hodJobResult = "https://api.havenondemand.com/1/job/result/"; + private String hodJobStatus = "https://api.havenondemand.com/1/job/status/"; private boolean getJobID = true; private String version = "v1"; private boolean isBusy = false; @@ -65,7 +66,7 @@ public HODClient(String apiKey, IHODClientCallback callback) { this.apiKey = apiKey; this.version = "v1"; mCallback = callback; - initializeHTTP(); + initializeHTTP();; } private void initializeHTTP() { hodApp = new HODApps(); @@ -83,42 +84,41 @@ private void initializeHTTP() { } public void GetJobResult(String jobID) { httpMethod = HTTP_METHOD.GET; - String queryStr = hodJobResult; - queryStr += jobID; + String queryStr = String.format("%s%s", hodJobResult, jobID); getJobID = false; new MakeAsyncActivitiesTask().execute(null, queryStr, ""); } - public void GetRequest(Map param, String iodApp, REQ_MODE mode) { - if (!isBusy) { - httpMethod = HTTP_METHOD.GET; - String queryStr = hodBase; - if (mode == REQ_MODE.SYNC) { - queryStr += "sync/"; - getJobID = false; - } else { - queryStr += "async/"; - getJobID = true; - } - queryStr += iodApp; - queryStr += "/" + version; - new MakeAsyncActivitiesTask().execute(param, queryStr, ""); + public void GetJobStatus(String jobID) { + httpMethod = HTTP_METHOD.GET; + String queryStr = String.format("%s%s", hodJobStatus, jobID); + getJobID = false; + new MakeAsyncActivitiesTask().execute(null, queryStr, ""); + } + public void GetRequest(Map params, String hodApp, REQ_MODE mode) { + httpMethod = HTTP_METHOD.GET; + String endPoint = hodBase; + if (mode == REQ_MODE.SYNC) { + endPoint += String.format("sync/%s/%s", hodApp, version); + getJobID = false; + } + else { + endPoint += String.format("async/%s/%s", hodApp, version); + getJobID = true; } + new MakeAsyncActivitiesTask().execute(params, endPoint, ""); } - public void PostRequest(Map param, String iodApp, REQ_MODE mode) { - if (!isBusy) { - httpMethod = HTTP_METHOD.POST; - String queryStr = hodBase; - if (mode == REQ_MODE.SYNC) { - queryStr += "sync/"; - getJobID = false; - } else { - queryStr += "async/"; - getJobID = true; - } - queryStr += iodApp; - queryStr += "/" + version; - new MakeAsyncActivitiesTask().execute(param, queryStr, ""); + public void PostRequest(Map params, String hodApp, REQ_MODE mode) { + httpMethod = HTTP_METHOD.POST; + String endPoint = hodBase; + if (mode == REQ_MODE.SYNC) { + endPoint += String.format("sync/%s/%s", hodApp, version); + getJobID = false; + } + else { + endPoint += String.format("async/%s/%s", hodApp, version); + getJobID = true; } + new MakeAsyncActivitiesTask().execute(params, endPoint, ""); } private void ParseResponse(String response) { if (getJobID) @@ -135,36 +135,36 @@ class MakeAsyncActivitiesTask extends AsyncTask { protected String doInBackground(Object... params) { isError = false; - isBusy = true; String url = ""; URI uri; if (httpMethod == HTTP_METHOD.GET) { - url = params[1] + "?apikey=" + apiKey; + url = String.format("%s?apikey=%s", params[1], apiKey); if (params[0] != null) { Map map = (Map) params[0]; for (Map.Entry e : map.entrySet()) { String key = e.getKey(); - if (key.equals("arrays")) { - Map submap = (Map) e.getValue(); - for (Map.Entry m : submap.entrySet()) { - String subKey = m.getKey(); - String subValue = m.getValue(); - String[] itemArr = subValue.split(","); - for (String item : itemArr) { - url += "&"; - url += subKey; - url += "="; - url += item.trim(); + if (key.equals("file")) { + isError = true; + return "Failed. File upload must be used with PostRequest method."; + } + Object val = e.getValue(); + String type = val.getClass().getName(); + if (type.equals("java.util.ArrayList")) { + for (String m : (ArrayList) val) { + try { + String value = URLEncoder.encode(m, "utf-8"); + url += String.format("&%s=%s", key, value); + } catch (UnsupportedEncodingException ex) { + isError = true; + return ex.getMessage(); } } } else { - String value = e.getValue().toString(); - url += "&"; - url += key; - url += "="; try { - url += URLEncoder.encode(value, "utf-8"); + String value = URLEncoder.encode(val.toString(), "utf-8"); + url += String.format("&%s=%s", key, value); } catch (UnsupportedEncodingException ex) { + isError = true; return ex.getMessage(); } } @@ -190,26 +190,51 @@ else if (httpMethod == HTTP_METHOD.POST) { reqEntity.addPart("apikey", new StringBody(apiKey, ContentType.TEXT_PLAIN)); for (Map.Entry e : map.entrySet()) { String key = e.getKey(); - if (key.equals("file")) { - String fileFullName = (String)e.getValue(); - String fileName = fileFullName.substring(fileFullName.lastIndexOf("/") + 1); - File pFile = new File(fileFullName); - Uri pUri = Uri.fromFile(pFile); - String mimeType = getMimeType(pUri.toString()); - ContentType type = ContentType.create(mimeType, Consts.ISO_8859_1); - reqEntity.addBinaryBody("file", pFile, type, fileName); - } else if (key.equals("arrays")) { - Map submap = (Map)e.getValue(); - for (Map.Entry m : submap.entrySet()) { - String subKey = m.getKey(); - String subValue = m.getValue(); - String[] itemArr = subValue.split(","); - for (String item : itemArr) - reqEntity.addPart(subKey, new StringBody(item.trim(), ContentType.TEXT_PLAIN)); + Object val = e.getValue(); + String objType = val.getClass().getName(); + if (objType.equals("java.util.ArrayList")) { + if (key.equals("file")) { + for (String m : (ArrayList) val) { + String fileName = m.substring(m.lastIndexOf("/") + 1); + File pFile = new File(m); + if (pFile.exists()) { + Uri pUri = Uri.fromFile(pFile); + String mimeType = getMimeType(pUri.toString()); + ContentType type = ContentType.create(mimeType, Consts.ISO_8859_1); + reqEntity.addBinaryBody("file", pFile, type, fileName); + } else { + isError = true; + Log.e("HODClient", "Failed. File not found"); + return "Failed. File not found"; + } + } + } else { + for (String m : (ArrayList) val) { + ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8); + StringBody value = new StringBody(m.toString(), contentType); + reqEntity.addPart(key, value); + } } } else { - String value = e.getValue().toString(); - reqEntity.addPart(key, new StringBody(value, ContentType.TEXT_PLAIN)); + if (key.equals("file")) { + String fileFullName = val.toString(); + String fileName = fileFullName.substring(fileFullName.lastIndexOf("/") + 1); + File pFile = new File(fileFullName); + if (pFile.exists()) { + Uri pUri = Uri.fromFile(pFile); + String mimeType = getMimeType(pUri.toString()); + ContentType type = ContentType.create(mimeType, Consts.ISO_8859_1); + reqEntity.addBinaryBody("file", pFile, type, fileName); + } else { + isError = true; + Log.e("HODClient", "Failed. File not found"); + return "Failed. File not found"; + } + } else { + ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8); + StringBody value = new StringBody(val.toString(), contentType); + reqEntity.addPart(key, value); + } } } httpPost.setEntity(reqEntity.build()); @@ -247,6 +272,7 @@ else if (httpMethod == HTTP_METHOD.POST) { isError = true; return e.getMessage(); } + //return null; } @Override @@ -256,7 +282,6 @@ protected void onProgressUpdate(String... unsued) { @Override protected void onPostExecute(String sResponse) { - isBusy = false; if (isError) { ParseError(sResponse); } else { @@ -270,4 +295,4 @@ private static String getMimeType(String url) { String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); return mimeType; } -} \ No newline at end of file +} diff --git a/hodresponseparser/.gitignore b/hodresponseparser/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/hodresponseparser/.gitignore @@ -0,0 +1 @@ +/build diff --git a/hodresponseparser/build.gradle b/hodresponseparser/build.gradle new file mode 100644 index 0000000..aa24ac5 --- /dev/null +++ b/hodresponseparser/build.gradle @@ -0,0 +1,49 @@ +apply plugin: 'com.android.library' +ext { + bintrayRepo = 'maven' + bintrayName = 'hodresponseparser' + + publishedGroupId = 'com.havenondemand' + libraryName = 'hodresponseparser' + artifact = 'hodresponseparser' + + libraryDescription = 'A parser library for parsing HavenOnDemand APIs\' response on Android' + + siteUrl = 'https://www.havenondemand.com' + gitUrl = '' + + libraryVersion = '2.0' + + developerId = 'PV' + developerName = 'Phong Vu' + developerEmail = 'phong.vu@hpe.com' + + licenseName = 'MIT license' + licenseUrl = '' + allLicenses = ["MIT"] +} +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + minSdkVersion 10 + targetSdkVersion 23 + versionCode 3 + versionName "2.1" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile files('libs/gson-1.7.1.jar') +} + +apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' +apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' \ No newline at end of file diff --git a/hodresponseparser/hodresponseparser.iml b/hodresponseparser/hodresponseparser.iml new file mode 100644 index 0000000..666fe1a --- /dev/null +++ b/hodresponseparser/hodresponseparser.iml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hodresponseparser/libs/LICENSE.txt b/hodresponseparser/libs/LICENSE.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/hodresponseparser/libs/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/hodresponseparser/libs/NOTICE.txt b/hodresponseparser/libs/NOTICE.txt new file mode 100644 index 0000000..8b8c12a --- /dev/null +++ b/hodresponseparser/libs/NOTICE.txt @@ -0,0 +1,3 @@ +This software includes code from IntelliJ IDEA Community Edition +Copyright (C) JetBrains s.r.o. +http://www.jetbrains.com/idea/ diff --git a/hodresponseparser/libs/gson-1.7.1.jar b/hodresponseparser/libs/gson-1.7.1.jar new file mode 100644 index 0000000..acd16c0 Binary files /dev/null and b/hodresponseparser/libs/gson-1.7.1.jar differ diff --git a/hodresponseparser/proguard-rules.pro b/hodresponseparser/proguard-rules.pro new file mode 100644 index 0000000..45ccca3 --- /dev/null +++ b/hodresponseparser/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/vanphongvu/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/hodresponseparser/src/main/AndroidManifest.xml b/hodresponseparser/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a887641 --- /dev/null +++ b/hodresponseparser/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/hodresponseparser/src/main/java/hod/response/parser/AddToTextIndexResponse.java b/hodresponseparser/src/main/java/hod/response/parser/AddToTextIndexResponse.java new file mode 100644 index 0000000..6f8caaa --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/AddToTextIndexResponse.java @@ -0,0 +1,17 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class AddToTextIndexResponse { + public String index; //(string ) The text index that the file was indexed to. + public List references; // ( array[References] ) Files indexed + + public class References + { + public int id; + public String reference; //(string , optional) File reference. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/AnomalyDetectionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/AnomalyDetectionResponse.java new file mode 100644 index 0000000..5419fb5 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/AnomalyDetectionResponse.java @@ -0,0 +1,28 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 3/29/16. + */ +public class AnomalyDetectionResponse { + List result; + + public class Result + { + long row; + double row_anomaly_score; + List anomalies; + } + public class Anomaly + { + String type; + double anomaly_score; + List columns; + } + class Column + { + String column; + String value; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/AutoCompleteResponse.java b/hodresponseparser/src/main/java/hod/response/parser/AutoCompleteResponse.java new file mode 100644 index 0000000..16eaac9 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/AutoCompleteResponse.java @@ -0,0 +1,10 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class AutoCompleteResponse { + public List words; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/BarcodeRecognitionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/BarcodeRecognitionResponse.java new file mode 100644 index 0000000..1969aa4 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/BarcodeRecognitionResponse.java @@ -0,0 +1,26 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class BarcodeRecognitionResponse { + + public List barcode; + public class BarcodeAdditionalInformation + { + public String country; + } + + public class Barcode + { + public String text; + public String barcode_type; + public Integer left; + public Integer top; + public Integer width; + public Integer height; + public BarcodeAdditionalInformation additional_information; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/CancelConnectorResponse.java b/hodresponseparser/src/main/java/hod/response/parser/CancelConnectorResponse.java new file mode 100644 index 0000000..efbf11a --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/CancelConnectorResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class CancelConnectorResponse { + public String connector; + public Boolean stopped_schedule; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ConceptExtractionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ConceptExtractionResponse.java new file mode 100644 index 0000000..70c4f53 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ConceptExtractionResponse.java @@ -0,0 +1,16 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ConceptExtractionResponse { + public List concepts; // (array[Concepts] ) A result concept identified in the results set. + + public class Concepts + { + public String concept; //(string) The text of the identified concept. + public int occurrences; // (number) The total number of occurrences of this element in the results set. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ConnectorHistoryResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ConnectorHistoryResponse.java new file mode 100644 index 0000000..494c302 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ConnectorHistoryResponse.java @@ -0,0 +1,35 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ConnectorHistoryResponse { + public List history; + public class History + { + public String connector; + public Document_counts document_counts; + public String error; + public String failed; + public String process_end_time; // Format: DD/MM/YYYY HH:mm:ss Z. + public String process_start_time; // Format: DD/MM/YYYY HH:mm:ss Z. + public String start_time; // Format: DD/MM/YYYY HH:mm:ss Z. + public String queued_time; // Format: DD/MM/YYYY HH:mm:ss Z. + public String status; // + public double time_in_queue; // + public double time_processing; // + public String token; // + } + public class Document_counts + { + public int added; + public int deleted; + public int errors; + public int ingest_added; + public int ingest_deleted; + public int ingest_failed; + } + +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ConnectorStatusResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ConnectorStatusResponse.java new file mode 100644 index 0000000..9b37e2d --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ConnectorStatusResponse.java @@ -0,0 +1,35 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ConnectorStatusResponse { + public String connector; // (String ) The name of the connector. + public String status; // ( String ) The current state of the connector job. + public Document_counts document_counts; // ( Document_counts , optional) Information about documents processed during connector job. + public String error; // ( String , optional) Error message for this connector job. + public String failed; // (String , optional) The failed reason for this connector job. + public String process_end_time; // (String , optional) The time when connector job finished processing.Format: DD/MM/YYYY HH:mm:ss Z. + public String process_start_time; // (String , optional) The time when connector job started being processed.Format: DD/MM/YYYY HH:mm:ss Z. + public String start_time; // ( String , optional) The last time when connector job has been updated or processed.Format: DD/MM/YYYY HH:mm:ss Z. + public String queued_time; // (String , optional) The time when connector job has been put on the queue.Format: DD/MM/YYYY HH:mm:ss Z. + public double time_in_queue; // (number , optional) The number of seconds the connector job spent in the queue. + public double time_processing; // (number , optional) The number of seconds spent processing the connector job. + public String token; // ( String , optional) Start connector token. + public Schedule schedule; // ( Schedule , optional) Schedule information for this connector. + public class Document_counts + { + public int added; + public int deleted; + public int errors; + public int ingest_added; + public int ingest_deleted; + public int ingest_failed; + } + public class Schedule + { + public String last_run_time; // (String or null , optional) The last time the connector was scheduled to run.Format: DD/MM/YYYY HH:mm:ss Z. + public String next_run_time; // (String or null , optional) The next time the connector is scheduled to run.Format: DD/MM/YYYY HH:mm:ss Z. + public int occurrences_remaining; // (number , optional) The number occurrences remaining for your connector schedule.If occurrences is unlimited, this value is -1. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/CreateConnectorResponse.java b/hodresponseparser/src/main/java/hod/response/parser/CreateConnectorResponse.java new file mode 100644 index 0000000..219e6e7 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/CreateConnectorResponse.java @@ -0,0 +1,18 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class CreateConnectorResponse { + public String connector; // ( string ) The name of the connector. + public Download_link download_link; // ( Download_link , optional) Object of download links to available connector installers for different operating systems and CPU architectures. This will only be available if created connector is an "on-site" flavor connector. + public String message; // ( string ) Indicates that the connector was created. + + public class Download_link + { + public String linux_x86; // ( string , optional) Download link to Linux 32-bit connector installer. + public String linux_x86_64; // ( string , optional) Download link to Linux 64-bit connector installer. + public String windows_x86; // ( string , optional) Download link to Windows 32-bit connector installer. + public String windows_x86_64; // ( string , optional) Download link to Windows 64-bit connector installer. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/CreateQueryProfileResponse.java b/hodresponseparser/src/main/java/hod/response/parser/CreateQueryProfileResponse.java new file mode 100644 index 0000000..91456aa --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/CreateQueryProfileResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class CreateQueryProfileResponse { + public String message; //( string ) Indicates that the query profile was created. + public String query_profile; // ( string ) Query profile name. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/CreateTextIndexResponse.java b/hodresponseparser/src/main/java/hod/response/parser/CreateTextIndexResponse.java new file mode 100644 index 0000000..4f629de --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/CreateTextIndexResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class CreateTextIndexResponse { + public String index; //(string , optional) The name of the new index. + public String message; //( string , optional) Indicates that the index was created. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/DeleteConnectorResponse.java b/hodresponseparser/src/main/java/hod/response/parser/DeleteConnectorResponse.java new file mode 100644 index 0000000..40e3684 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/DeleteConnectorResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class DeleteConnectorResponse { + public String connector; // ( string ) The name of the connector. + public Boolean deleted; // ( boolean ) Indicates that the connector was deleted successfully. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/DeleteFromTextIndexResponse.java b/hodresponseparser/src/main/java/hod/response/parser/DeleteFromTextIndexResponse.java new file mode 100644 index 0000000..12762f5 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/DeleteFromTextIndexResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class DeleteFromTextIndexResponse { + public int documents_deleted; // ( integer ) The number of deleted documents. + public String index; // ( string ) The index the document was deleted from. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/DeleteQueryProfileResponse.java b/hodresponseparser/src/main/java/hod/response/parser/DeleteQueryProfileResponse.java new file mode 100644 index 0000000..4ae9ceb --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/DeleteQueryProfileResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class DeleteQueryProfileResponse { + public String message; //(string ) Indicates that the query profile was deleted successfully. + public String query_profile; //(string ) The name of the query profile. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/DeleteTextIndexResponse.java b/hodresponseparser/src/main/java/hod/response/parser/DeleteTextIndexResponse.java new file mode 100644 index 0000000..df85cfa --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/DeleteTextIndexResponse.java @@ -0,0 +1,10 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class DeleteTextIndexResponse { + public String confirm; //(string , optional) The confirmation hash required for deletion. + public Boolean deleted; //( boolean ) Whether or not the index was deleted. + public String index; //( string , optional) Index name +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ExpandContainerResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ExpandContainerResponse.java new file mode 100644 index 0000000..867e00f --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ExpandContainerResponse.java @@ -0,0 +1,16 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ExpandContainerResponse { + public List files; //A list of files and object store references. + + public class Files + { + public String name; // The name of the extracted file. + public String reference; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ExpandTermsResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ExpandTermsResponse.java new file mode 100644 index 0000000..25871e8 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ExpandTermsResponse.java @@ -0,0 +1,16 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ExpandTermsResponse { + public List terms; // ( array[Terms] ) The details of the expanded terms. + + public class Terms + { + public int documents; //(integer , optional) The number of documents that the expanded term occurs in. + public String term; //(string ) The expanded term. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/FaceDetectionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/FaceDetectionResponse.java new file mode 100644 index 0000000..e3a540c --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/FaceDetectionResponse.java @@ -0,0 +1,22 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class FaceDetectionResponse { + public List face; // (array[Face]) The details of a detected face. + + public class Face { + public Integer left; // (integer) The position of the left edge of the bounding box for the face, in pixels from the left edge of the image (for PDF images, position is in points). + public Integer top; // (integer) The position of the top edge of the bounding box for the face, in pixels from the top edge of the image (for PDF images, position is in points). + public Integer width; // (integer) The width of the bounding box for the face, in pixels (or points for PDF images). + public Integer height; // (integer) The height of the bounding box for the face (or points for PDF images). + public AdditionalInformation additional_information; // (Additional_information, optional) + } + + public class AdditionalInformation { + public String age; // (string, optional) Age range of the face + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/FindRelatedConceptsResponse.java b/hodresponseparser/src/main/java/hod/response/parser/FindRelatedConceptsResponse.java new file mode 100644 index 0000000..d4b1787 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/FindRelatedConceptsResponse.java @@ -0,0 +1,19 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class FindRelatedConceptsResponse { + public List entities; //(array[Entities] ) A result term or phrase identified in the results set. + + public class Entities + { + public int cluster; //(number ) The cluster into which the phrase has been grouped.This value allows you to cluster the elements according to their occurrence. + public int docs_with_all_terms; //(number ) The number of documents of the results set in which all terms of this element appear. + public int docs_with_phrase; //( number ) The number of documents in the result set in which this element appears as a phrase. + public int occurrences; //(number) The total number of occurrences of this element in the results set. + public String text; //(string) The text of the identified term or phrase. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/GetCommonNeighborsResponse.java b/hodresponseparser/src/main/java/hod/response/parser/GetCommonNeighborsResponse.java new file mode 100644 index 0000000..0263647 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/GetCommonNeighborsResponse.java @@ -0,0 +1,21 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class GetCommonNeighborsResponse { + public List nodes; + public class Nodes + { + public Attributes attributes; + public int id; + public int commonality; + public int sort_value; + } + public class Attributes + { + public String name; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/GetNeighborsResponse.java b/hodresponseparser/src/main/java/hod/response/parser/GetNeighborsResponse.java new file mode 100644 index 0000000..aab5dd7 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/GetNeighborsResponse.java @@ -0,0 +1,38 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class GetNeighborsResponse { + public List neighbors; + + public class Neighbors + { + public Target target; + public Source source; + public List nodes; + } + + public class Nodes + { + public Attributes attributes; + public int id; + public double sort_value; + } + public class Attributes + { + public String name; + } + public class Target + { + public int id; + public Attributes attributes; + } + public class Source + { + public int id; + public Attributes attributes; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/GetNodesResponse.java b/hodresponseparser/src/main/java/hod/response/parser/GetNodesResponse.java new file mode 100644 index 0000000..fdc5062 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/GetNodesResponse.java @@ -0,0 +1,20 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class GetNodesResponse { + public List nodes; + public class Nodes + { + public Attributes attributes; + public int id; + public int sort_value; + } + public class Attributes + { + public String name; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/GetShortestPathResponse.java b/hodresponseparser/src/main/java/hod/response/parser/GetShortestPathResponse.java new file mode 100644 index 0000000..248d18b --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/GetShortestPathResponse.java @@ -0,0 +1,30 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class GetShortestPathResponse { + public List edges; + public List nodes; + + public class Edges + { + public Attributes attributes; + public int length; //(number ) Length/weight/cost of edge. + public int source; //( integer ) Source node ID. + public int target; //( integer ) Target node ID. + } + + public class Attributes + { + public double weight; + } + + public class Nodes + { + public Attributes attributes; + public int id; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/GetSubgraphResponse.java b/hodresponseparser/src/main/java/hod/response/parser/GetSubgraphResponse.java new file mode 100644 index 0000000..67976ac --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/GetSubgraphResponse.java @@ -0,0 +1,30 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class GetSubgraphResponse { + public List edges; + public List nodes; + + public class Edges + { + public Attributes attributes; + public int source; + public int target; + } + + public class Attributes + { + public double weight; + } + + public class Nodes + { + public Attributes attributes; + public int id; + } + +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/HODErrorCode.java b/hodresponseparser/src/main/java/hod/response/parser/HODErrorCode.java new file mode 100644 index 0000000..25c5264 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/HODErrorCode.java @@ -0,0 +1,13 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 1/5/16. + */ +public class HODErrorCode { + public static final int IN_PROGRESS = 1610; + public static final int QUEUED = 1620; + public static final int NONSTANDARD_RESPONSE = 1630; + public static final int INVALID_PARAM = 1640; + public static final int INVALID_HOD_RESPONSE = 1650; + public static final int UNKNOWN_ERROR = 1660; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/HODErrorObject.java b/hodresponseparser/src/main/java/hod/response/parser/HODErrorObject.java new file mode 100644 index 0000000..1ffdde2 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/HODErrorObject.java @@ -0,0 +1,11 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 1/5/16. + */ +public class HODErrorObject { + public int error = 0; + public String reason = ""; + public String detail = ""; + public String jobID = ""; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/HODResponse.java b/hodresponseparser/src/main/java/hod/response/parser/HODResponse.java new file mode 100644 index 0000000..d26ed54 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/HODResponse.java @@ -0,0 +1,23 @@ +package hod.response.parser; + +import java.util.List; + +// IOD API Response Models + +public class HODResponse { + + public static class Action + { + public Object result; + public String status; + public String action; + public String version; + } + + public static class JobBatchResponse + { + public List actions; + public String jobID; + public String status; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/HODResponseException.java b/hodresponseparser/src/main/java/hod/response/parser/HODResponseException.java new file mode 100644 index 0000000..4062c1f --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/HODResponseException.java @@ -0,0 +1,14 @@ +package hod.response.parser; + +public class HODResponseException extends RuntimeException { + + public int error = 0; + public String reason = ""; + public String detail = ""; + public HODResponseException(int e, String r, String d) { + super(r); + error = e; + reason = r; + detail = d; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/HODResponseParser.java b/hodresponseparser/src/main/java/hod/response/parser/HODResponseParser.java new file mode 100644 index 0000000..e8af040 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/HODResponseParser.java @@ -0,0 +1,578 @@ +package hod.response.parser; + +import com.google.gson.Gson; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class HODResponseParser { + private List errors; + private Gson gsonObj; + public HODResponseParser() + { + errors = new ArrayList(); + gsonObj = new Gson(); + } + private void ResetErrorList() + { + errors.clear(); + } + private void AddError(HODErrorObject error) + { + errors.add(error); + } + public List GetLastError() + { + return errors; + } + public String ParseJobID(String jsonString) + { + String jobID = ""; + try { + JSONObject mainObject = new JSONObject(jsonString); + if (!mainObject.isNull("jobID")) { + jobID = mainObject.getString("jobID"); + } else { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.INVALID_HOD_RESPONSE; + error.reason = "Unrecognized response from HOD"; + this.AddError(error); + } + } catch (Exception ex) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.UNKNOWN_ERROR; + error.reason = "Unknown error"; + error.detail = ex.getMessage(); + this.AddError(error); + return jobID; + } + return jobID; + } + private String getResult(String jsonStr) { + String result = jsonStr; + if (jsonStr.length() == 0) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.INVALID_HOD_RESPONSE; + error.reason = "Empty response"; + this.AddError(error); + return null; + } + try { + JSONObject mainObject = new JSONObject(jsonStr); + JSONObject actions = null; + if (!mainObject.isNull("actions")) { + actions = mainObject.getJSONArray("actions").getJSONObject(0); + String status = actions.getString("status"); + if (status.equals("finished")) + result = actions.getJSONObject("result").toString(); + else if (status.equals("failed")) { + JSONArray errorArr = actions.getJSONArray("errors"); + int count = errorArr.length(); + for (int i = 0; i < count; i++) { + JSONObject error = errorArr.getJSONObject(i); + HODErrorObject err = new HODErrorObject(); + err.error = error.getInt("error"); + err.reason = error.getString("reason"); + if (!error.isNull("detail")) + err.detail = error.getString("detail"); + this.AddError(err); + } + return null; + } else if (status.equals("queued")) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.QUEUED; + error.reason = "Task is in queue."; + error.jobID = mainObject.getString("jobID"); + this.AddError(error); + return null; + } else if (status.equals("in progress")) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.IN_PROGRESS; + error.reason = "Task is in progress."; + error.jobID = mainObject.getString("jobID"); + this.AddError(error); + return null; + } else { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.UNKNOWN_ERROR; + error.reason = "Unknown error"; + error.jobID = mainObject.getString("jobID"); + this.AddError(error); + return null; + } + } + } catch (Exception ex) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.INVALID_HOD_RESPONSE; + error.reason = "Unrecognized response from HOD"; + error.detail = ex.getMessage(); + this.AddError(error); + return null; + } + return result; + } + public SpeechRecognitionResponse ParseSpeechRecognitionResponse(String jsonStr) + { + SpeechRecognitionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, SpeechRecognitionResponse.class); + } + return obj; + } + public CancelConnectorResponse ParseCancelConnectorResponse(String jsonStr) { + CancelConnectorResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, CancelConnectorResponse.class); + } + return obj; + } + public ConnectorHistoryResponse ParseConnectorHistoryResponse(String jsonStr) { + ConnectorHistoryResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ConnectorHistoryResponse.class); + } + return obj; + } + public ConnectorStatusResponse ParseConnectorStatusResponse(String jsonStr) { + ConnectorStatusResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ConnectorStatusResponse.class); + } + return obj; + } + public CreateConnectorResponse ParseCreateConnectorResponse(String jsonStr) { + CreateConnectorResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, CreateConnectorResponse.class); + } + return obj; + } + public DeleteConnectorResponse ParseDeleteConnectorResponse(String jsonStr) { + DeleteConnectorResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, DeleteConnectorResponse.class); + } + return obj; + } + public RetrieveConnectorConfigurationAttributeResponse ParseRetrieveConnectorConfigurationAttributeResponse(String jsonStr) { + RetrieveConnectorConfigurationAttributeResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, RetrieveConnectorConfigurationAttributeResponse.class); + } + return obj; + } + public RetrieveConnectorConfigurationFileResponse ParseRetrieveConnectorConfigurationFileResponse(String jsonStr) { + RetrieveConnectorConfigurationFileResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, RetrieveConnectorConfigurationFileResponse.class); + } + return obj; + } + public StartConnectorResponse ParseStartConnectorResponse(String jsonStr) { + StartConnectorResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, StartConnectorResponse.class); + } + return obj; + } + public StopConnectorResponse ParseStopConnectorResponse(String jsonStr) { + StopConnectorResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, StopConnectorResponse.class); + } + return obj; + } + public UpdateConnectorResponse ParseUpdateConnectorResponse(String jsonStr) { + UpdateConnectorResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, UpdateConnectorResponse.class); + } + return obj; + } + public ExpandContainerResponse ParseExpandContainerResponse(String jsonStr) { + ExpandContainerResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ExpandContainerResponse.class); + } + return obj; + } + public StoreObjectResponse ParseStoreObjectResponse(String jsonStr) { + StoreObjectResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, StoreObjectResponse.class); + } + return obj; + } + public ViewDocumentResponse ParseViewDocumentResponse(String jsonStr) { + ViewDocumentResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ViewDocumentResponse.class); + } + return obj; + } + public GetCommonNeighborsResponse ParseGetCommonNeighborsResponse(String jsonStr) { + GetCommonNeighborsResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, GetCommonNeighborsResponse.class); + } + return obj; + } + public GetNeighborsResponse ParseGetNeighborsResponse(String jsonStr) { + GetNeighborsResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, GetNeighborsResponse.class); + } + return obj; + } + public GetNodesResponse ParseGetNodesResponse(String jsonStr) { + GetNodesResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, GetNodesResponse.class); + } + return obj; + } + public GetShortestPathResponse ParseGetShortestPathResponse(String jsonStr) { + GetShortestPathResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, GetShortestPathResponse.class); + } + return obj; + } + public GetSubgraphResponse ParseGetSubgraphResponse(String jsonStr) { + GetSubgraphResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, GetSubgraphResponse.class); + } + return obj; + } + public SuggestLinksResponse ParseSuggestLinksResponse(String jsonStr) { + SuggestLinksResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, SuggestLinksResponse.class); + } + return obj; + } + public SummarizeGraphResponse ParseSummarizeGraphResponse(String jsonStr) { + SummarizeGraphResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, SummarizeGraphResponse.class); + } + return obj; + } + public OCRDocumentResponse ParseOCRDocumentResponse(String jsonStr) { + OCRDocumentResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, OCRDocumentResponse.class); + } + return obj; + } + public BarcodeRecognitionResponse ParseBarcodeRecognitionResponse(String jsonStr) { + BarcodeRecognitionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, BarcodeRecognitionResponse.class); + } + return obj; + } + public FaceDetectionResponse ParseFaceDetectionResponse(String jsonStr) { + FaceDetectionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, FaceDetectionResponse.class); + } + return obj; + } + public ImageRecognitionResponse ParseImageRecognitionResponse(String jsonStr) { + ImageRecognitionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ImageRecognitionResponse.class); + } + return obj; + } + public PredictResponse ParsePredictResponse(String jsonStr) { + PredictResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, PredictResponse.class); + } + return obj; + } + public RecommendResponse ParseRecommendResponse(String jsonStr) { + RecommendResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, RecommendResponse.class); + } + return obj; + } + public TrainPredictionResponse ParseTrainPredictionResponse(String jsonStr) { + TrainPredictionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, TrainPredictionResponse.class); + } + return obj; + } + public CreateQueryProfileResponse ParseCreateQueryProfileResponse(String jsonStr) { + CreateQueryProfileResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, CreateQueryProfileResponse.class); + } + return obj; + } + public DeleteQueryProfileResponse ParseDeleteQueryProfileResponse(String jsonStr) { + DeleteQueryProfileResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, DeleteQueryProfileResponse.class); + } + return obj; + } + public RetrieveQueryProfileResponse ParseRetrieveQueryProfileResponse(String jsonStr) { + RetrieveQueryProfileResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, RetrieveQueryProfileResponse.class); + } + return obj; + } + public UpdateQueryProfileResponse ParseUpdateQueryProfileResponse(String jsonStr) { + UpdateQueryProfileResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, UpdateQueryProfileResponse.class); + } + return obj; + } + public FindRelatedConceptsResponse ParseFindRelatedConceptsResponse(String jsonStr) { + FindRelatedConceptsResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, FindRelatedConceptsResponse.class); + } + return obj; + } + public AutoCompleteResponse ParseAutoCompleteResponse(String jsonStr) { + AutoCompleteResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, AutoCompleteResponse.class); + } + return obj; + } + public ConceptExtractionResponse ParseConceptExtractionResponse(String jsonStr) { + ConceptExtractionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ConceptExtractionResponse.class); + } + return obj; + } + public ExpandTermsResponse ParseExpandTermsResponse(String jsonStr) { + ExpandTermsResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ExpandTermsResponse.class); + } + return obj; + } + public HighlightTextResponse ParseHighlightTextResponse(String jsonStr) { + HighlightTextResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, HighlightTextResponse.class); + } + return obj; + } + public LanguageIdentificationResponse ParseLanguageIdentificationResponse(String jsonStr) { + LanguageIdentificationResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, LanguageIdentificationResponse.class); + } + return obj; + } + public SentimentAnalysisResponse ParseSentimentAnalysisResponse(String jsonStr) { + SentimentAnalysisResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, SentimentAnalysisResponse.class); + } + return obj; + } + public TextTokenizationResponse ParseTextTokenizationResponse(String jsonStr) { + TextTokenizationResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, TextTokenizationResponse.class); + } + return obj; + } + public AddToTextIndexResponse ParseAddToTextIndexResponse(String jsonStr) { + AddToTextIndexResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, AddToTextIndexResponse.class); + } + return obj; + } + public CreateTextIndexResponse ParseCreateTextIndexResponse(String jsonStr) { + CreateTextIndexResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, CreateTextIndexResponse.class); + } + return obj; + } + public DeleteTextIndexResponse ParseDeleteTextIndexResponse(String jsonStr) { + DeleteTextIndexResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, DeleteTextIndexResponse.class); + } + return obj; + } + public DeleteFromTextIndexResponse ParseDeleteFromTextIndexResponse(String jsonStr) { + DeleteFromTextIndexResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, DeleteFromTextIndexResponse.class); + } + return obj; + } + public IndexStatusResponse ParseIndexStatusResponse(String jsonStr) { + IndexStatusResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, IndexStatusResponse.class); + } + return obj; + } + public ListResourcesResponse ParseListResourcesResponse(String jsonStr) { + ListResourcesResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, ListResourcesResponse.class); + } + return obj; + } + public RestoreTextIndexResponse ParseRestoreTextIndexResponse(String jsonStr) { + RestoreTextIndexResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, RestoreTextIndexResponse.class); + } + return obj; + } + public AnomalyDetectionResponse ParseAnomalyDetectionResponse(String jsonStr) { + AnomalyDetectionResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, AnomalyDetectionResponse.class); + } + return obj; + } + public TrendAnalysisResponse ParseTrendAnalysisResponse(String jsonStr) { + TrendAnalysisResponse obj = null; + String result = getResult(jsonStr); + if (result != null) { + obj = gsonObj.fromJson(result, TrendAnalysisResponse.class); + } + return obj; + } + public Object ParseCustomResponse(Class T, String jsonStr) + { + Object obj = null; + String result = jsonStr; + if (jsonStr.length() == 0) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.INVALID_HOD_RESPONSE; + error.reason = "Invalid response"; + this.AddError(error); + return obj; + } + try { + JSONObject mainObject = new JSONObject(jsonStr); + if (!mainObject.isNull("actions")) + { + JSONObject actions = mainObject.getJSONArray("actions").getJSONObject(0); + String status = actions.getString("status"); + if (status.equals("finished")) + result = actions.getJSONObject("result").toString(); + else if (status.equals("failed")) { + JSONArray errorArr = actions.getJSONArray("errors"); + int count = errorArr.length(); + for (int i = 0; i < count; i++) { + JSONObject error = errorArr.getJSONObject(i); + HODErrorObject err = new HODErrorObject(); + err.error = error.getInt("error"); + err.reason = error.getString("reason"); + if (!error.isNull("detail")) + err.detail = error.getString("detail"); + this.AddError(err); + } + return null; + } else if (status.equals("queued")) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.QUEUED; + error.reason = "Task is in queue."; + error.jobID = mainObject.getString("jobID"); + this.AddError(error); + return null; + } else if (status.equals("in progress")) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.IN_PROGRESS; + error.reason = "Task is in progress."; + error.jobID = mainObject.getString("jobID"); + this.AddError(error); + return null; + } else { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.UNKNOWN_ERROR; + error.reason = "Unknown error"; + error.jobID = mainObject.getString("jobID"); + this.AddError(error); + return null; + } + } + obj = gsonObj.fromJson(result, T); + } catch (Exception ex) { + HODErrorObject error = new HODErrorObject(); + error.error = HODErrorCode.INVALID_HOD_RESPONSE; + error.reason = "Unrecognized response from HOD"; + error.detail = ex.getMessage(); + this.AddError(error); + } + return obj; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/HighlightTextResponse.java b/hodresponseparser/src/main/java/hod/response/parser/HighlightTextResponse.java new file mode 100644 index 0000000..e1cd39f --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/HighlightTextResponse.java @@ -0,0 +1,8 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class HighlightTextResponse { + public String text; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ImageRecognitionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ImageRecognitionResponse.java new file mode 100644 index 0000000..dceabcc --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ImageRecognitionResponse.java @@ -0,0 +1,24 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class ImageRecognitionResponse { + + public List object; // (array[Object]) Details of a recognized object in the image. + + public class HODObject { + public String unique_name; // (string) The unique name of the object recognized from the database. + public String name; // (string) The descriptive name of the recognized object. + public String db; // (enum) The name of the recognition database that the recognized object is stored in. + public List corners; // (array[Corners]) The positions of the corners of a quadrilateral bounding box containing the recognized object. + } + + public class Corners { + public Integer x; // (integer) The horizontal position of the corner of the bounding box. + public Integer y; // (integer) The vertical position of the corner of the bounding box. + } + +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/IndexStatusResponse.java b/hodresponseparser/src/main/java/hod/response/parser/IndexStatusResponse.java new file mode 100644 index 0000000..5f2d9c3 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/IndexStatusResponse.java @@ -0,0 +1,11 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class IndexStatusResponse { + //public int 24hr_index_updates; // ( number ) The total number of document updates in the last 24 hours. + public int component_count; //( number ) The total number of index components contained in the text index (Haven OnDemand creates additional components when a text index grows larger than the component quota size for the flavor). + public int total_documents; //( number ) The total number of documents in the index. + public int total_index_size; //( number ) The total size of the index in bytes. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/LanguageIdentificationResponse.java b/hodresponseparser/src/main/java/hod/response/parser/LanguageIdentificationResponse.java new file mode 100644 index 0000000..772f476 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/LanguageIdentificationResponse.java @@ -0,0 +1,13 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class LanguageIdentificationResponse { + public String encoding; //( enum ) The identified encoding of the input text. + public String language; //( enum ) The identified language of the input text. + public String language_iso639_2b; //( enum ) The ISO639-2B code for the identified language of the input text, "UND" if the language could not be identified. + public List unicode_scripts; // (array[string] , optional) The UTF-8 character ranges that your input text includes. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ListResourcesResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ListResourcesResponse.java new file mode 100644 index 0000000..75178b4 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ListResourcesResponse.java @@ -0,0 +1,29 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ListResourcesResponse { + public List private_resources; //(array[Private_resources] ) List of private resources. + public List public_resources; // ( array[Public_resources] ) List of public resources. + + public class Private_resources + { + public String date_created; // (String ) The date the resource was created. + public String description; // (String or null , optional) The description of the resource. + public String flavor; // ( String or null , optional) The flavor of the resource. + public String resource; // ( String ) The resource name. + public String type; // ( String ) The type of resource. + public String display_name; // (String , optional) A friendly name for the resource. + public String resourceUUID; + } + + public class Public_resources + { + public String description; // (String , optional) The description of the resource. + public String resource; // ( String ) The resource name. + public String type; // ( String ) The type of resource. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/OCRDocumentResponse.java b/hodresponseparser/src/main/java/hod/response/parser/OCRDocumentResponse.java new file mode 100644 index 0000000..b5c9125 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/OCRDocumentResponse.java @@ -0,0 +1,18 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class OCRDocumentResponse { + public List text_block; // Details of a section of text found in the image. + public class TextBlock + { + public String text; // (string) The text extracted in this section of the image. + public Integer left; // (integer) The position of the left edge of the bounding box for the text. + public Integer top; // (integer) The position of the top edge of the bounding box for the text. + public Integer width; // (integer) The width of the bounding box for the text. + public Integer height; // (integer) The height of the bounding box for the text. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/PredictResponse.java b/hodresponseparser/src/main/java/hod/response/parser/PredictResponse.java new file mode 100644 index 0000000..460c581 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/PredictResponse.java @@ -0,0 +1,23 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class PredictResponse { + public List fields; // (array[Fields] ) Metadata definition of the data set, describing the structure of the dataset fields. + public List values; // (array[Values] ) The data set values. + + public class Fields + { + public String name; // (String ) The name of the field. + public int order; // ( integer ) The order of the field. + public String type; // ( String ) The type of the field. + } + + public class Values + { + public List row; // (array[String] , optional) An array of values.Ordered in correlation to the list of Fields Metadata. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/RecognizeSpeechResponse.java b/hodresponseparser/src/main/java/hod/response/parser/RecognizeSpeechResponse.java new file mode 100644 index 0000000..1638498 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/RecognizeSpeechResponse.java @@ -0,0 +1,14 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class RecognizeSpeechResponse { + public List document; // (array[Document]) The speech block transformed to text. + public class Document { + public Integer offset; // (integer, optional) The offset of the first word in this content section. + public String content; // (string) The extracted block of text from speech. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/RecommendResponse.java b/hodresponseparser/src/main/java/hod/response/parser/RecommendResponse.java new file mode 100644 index 0000000..cf9d060 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/RecommendResponse.java @@ -0,0 +1,32 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class RecommendResponse { + public List allRecommendations; // (array[Allrecommendations] , optional) The data set values. + public List fields; // (array[Fields] ) Metadata definition of the data set, describing the structure of the dataset fields. + + public class Allrecommendations + { + public List originalValues; // (array[String] , optional) An array of original record values.Ordered in correlation to the list of Fields Metadata. + public List recommendations; // ( array[Recommendations] , optional) An array of recommended records. + } + + public class Recommendations + { + public String confidence; // (number , optional) The confidence that the label will be as required + public String distance; // (number , optional) Distance between the original record to the recommended record. + public String new_prediction; // ( String , optional) Predicted field result according to prediction model. + public List recommendation; // ( array[String] , optional) An array of recommended record values.Ordered in correlation to the list of Fields Metadata. + } + + public class Fields + { + public String name; // (String ) The name of the field. + public int order; // ( integer ) The order of the field. + public String type; // ( String ) The type of the field. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/RestoreTextIndexResponse.java b/hodresponseparser/src/main/java/hod/response/parser/RestoreTextIndexResponse.java new file mode 100644 index 0000000..5da653e --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/RestoreTextIndexResponse.java @@ -0,0 +1,8 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class RestoreTextIndexResponse { + public String restored; //(string , optional) The name of the index created. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/RetrieveConnectorConfigurationAttributeResponse.java b/hodresponseparser/src/main/java/hod/response/parser/RetrieveConnectorConfigurationAttributeResponse.java new file mode 100644 index 0000000..c1b74d7 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/RetrieveConnectorConfigurationAttributeResponse.java @@ -0,0 +1,47 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class RetrieveConnectorConfigurationAttributeResponse { + public String name; //(String ) The name of the connector. + public String flavor; //( String ) The flavor of the connector. + public Config config; //(Config ) The configured attributes for this connector. + + public class Config + { + public ConfigObj config; // (object , optional) The configured config attributes for this connector. + public DestinationObj destination; // ( object , optional) The configured destination attributes for this connector. + public ScheduleObj schedule; // ( object , optional) The configured schedule attributes for this connector. + public CredentialsObj credentials; // ( object , optional) The configured credentials attributes for this connector. + public CredentialsPolicy credentials_policy; // ( object , optional) The configured credentials_policy attributes for this connector. + public String description; // ( String , optional) The connector description. + } + public class ConfigObj + { + public String url; + public int max_pages; + } + public class DestinationObj + { + public String action; + public String index; + } + public class ScheduleObj + { + public class frequency + { + public String frequency_type; + public double interval; + } + } + public class CredentialsObj + { + public String login_value; + public String password_value; + } + public class CredentialsPolicy + { + public String notification_email; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/RetrieveConnectorConfigurationFileResponse.java b/hodresponseparser/src/main/java/hod/response/parser/RetrieveConnectorConfigurationFileResponse.java new file mode 100644 index 0000000..09c13c1 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/RetrieveConnectorConfigurationFileResponse.java @@ -0,0 +1,13 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class RetrieveConnectorConfigurationFileResponse { + public String name; //(String ) The name of the connector. + public String flavor; //( String ) The flavor of the connector. + public String config; //( String ) The base64 encoded connector configuration. + public String licenseKey; //( String , optional) The license key for onsite flavor connectors only. + public String validation; //(String , optional) The connector validation key for onsite flavor connectors only. + public String verification; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/RetrieveQueryProfileResponse.java b/hodresponseparser/src/main/java/hod/response/parser/RetrieveQueryProfileResponse.java new file mode 100644 index 0000000..a444857 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/RetrieveQueryProfileResponse.java @@ -0,0 +1,19 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class RetrieveQueryProfileResponse { + public String query_profile; //(String ) The name of the query profile. + public String description; //(String or null ) Query profile description. + public String query_manipulation_index; //( String ) The name of the query manipulation index. + public Boolean promotions_enabled; //( Booleanean ) Whether to enable promotion. + public List promotion_categories; //(array[String] ) List of promotion categories. + public Boolean promotions_identified; //(Booleanean ) Whether to identify whether documents are a promotion or not. + public Boolean synonyms_enabled; //(Booleanean ) Whether to enable synonyms. + public List synonym_categories; //(array[String] ) List of synonym categories. + public Boolean blacklists_enabled; //(Booleanean ) Whether to enable blacklist. + public List blacklist_categories; //(array[String] ) List of blacklist categories. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/SentimentAnalysisResponse.java b/hodresponseparser/src/main/java/hod/response/parser/SentimentAnalysisResponse.java new file mode 100644 index 0000000..871bc26 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/SentimentAnalysisResponse.java @@ -0,0 +1,28 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class SentimentAnalysisResponse { + public List positive; + public List negative; + public Aggregate aggregate; + + public class Aggregate { + public String sentiment; // (enum) The sentiment value for the text. + public Double score; // (number) The mean confidence score for the sentiment entities (higher scores indicate a more likely sentiment match). Negative scores indicate negative sentiment. + } + + public class Entity { + public String sentiment; // ( string or null ) + public String topic; // ( string or null ) + public Double score; // (number) The confidence score for the match (higher scores indicate a more likely match). Negative scores indicate negative sentiment. + public String original_text; // (string) The original text of the extracted entity. + public String normalized_text; // (string) The text of the extracted entity, after character normalization. + public Double original_length; // (number) The original length of the extracted entity. + public Double normalized_length; // (number) The length of the extracted entity, after character normalization. + public String documentIndex; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/SpeechRecognitionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/SpeechRecognitionResponse.java new file mode 100644 index 0000000..b0553aa --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/SpeechRecognitionResponse.java @@ -0,0 +1,16 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class SpeechRecognitionResponse { + public List document; + public class Document { + public Integer offset; + public String content; + public Integer confidence; + public Integer duration; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/StartConnectorResponse.java b/hodresponseparser/src/main/java/hod/response/parser/StartConnectorResponse.java new file mode 100644 index 0000000..f579d10 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/StartConnectorResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class StartConnectorResponse { + public String connector; // The name of the connector. + public String token; +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/StopConnectorResponse.java b/hodresponseparser/src/main/java/hod/response/parser/StopConnectorResponse.java new file mode 100644 index 0000000..cf5bfe3 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/StopConnectorResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class StopConnectorResponse { + public String connector; // The name of the connector. + public String message; // Indicates that the connector is stopping. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/StoreObjectResponse.java b/hodresponseparser/src/main/java/hod/response/parser/StoreObjectResponse.java new file mode 100644 index 0000000..3838e30 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/StoreObjectResponse.java @@ -0,0 +1,8 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class StoreObjectResponse { + public String reference; // The object store reference of the extracted file. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/SuggestLinksResponse.java b/hodresponseparser/src/main/java/hod/response/parser/SuggestLinksResponse.java new file mode 100644 index 0000000..88f4dda --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/SuggestLinksResponse.java @@ -0,0 +1,35 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class SuggestLinksResponse { + public List suggestions; + + + public class Suggestions + { + public Source source; + public List nodes; + } + + public class Source + { + public int id; + public Attributes attributes; + } + + public class Attributes + { + public String name; + } + + public class Nodes + { + public Attributes attributes; + public int id; + public int sort_value; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/SummarizeGraphResponse.java b/hodresponseparser/src/main/java/hod/response/parser/SummarizeGraphResponse.java new file mode 100644 index 0000000..769b9b9 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/SummarizeGraphResponse.java @@ -0,0 +1,20 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/17/15. + */ +public class SummarizeGraphResponse { + public List attributes; + public int edges; + public int nodes; + + public class Attributes + { + public String data_type; + public String element_type; + public String name; + public int number; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/SupportedApps.java b/hodresponseparser/src/main/java/hod/response/parser/SupportedApps.java new file mode 100644 index 0000000..f87c753 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/SupportedApps.java @@ -0,0 +1,87 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 1/5/16. + */ +public class SupportedApps { + public final static String RECOGNIZE_SPEECH = "recognizespeech"; + + public final static String CANCEL_CONNECTOR_SCHEDULE = "cancelconnectorschedule"; + public final static String CONNECTOR_HISTORY = "connectorhistory"; + public final static String CONNECTOR_STATUS = "connectorstatus"; + public final static String CREATE_CONNECTOR = "createconnector"; + public final static String DELETE_CONNECTOR = "deleteconnector"; + public final static String RETRIEVE_CONFIG_ATTR = "retrieveconfig_attr"; + public final static String RETRIEVE_CONFIG_FILE = "retrieveconfig_file"; + public final static String START_CONNECTOR = "startconnector"; + public final static String STOP_CONNECTOR = "stopconnector"; + public final static String UPDATE_CONNECTOR = "updateconnector"; + + public final static String EXPAND_CONTAINER = "expandcontainer"; + public final static String STORE_OBJECT = "storeobject"; + //public final static String EXTRACT_TEXT = "extracttext"; + public final static String VIEW_DOCUMENT = "viewdocument"; + + public final static String OCR_DOCUMENT = "ocrdocument"; + public final static String RECOGNIZE_BARCODES = "recognizebarcodes"; + public final static String DETECT_FACES = "detectfaces"; + public final static String RECOGNIZE_IMAGES = "recognizeimages"; + + public final static String GET_COMMON_NEIGHBORS = "getcommonneighbors"; + public final static String GET_NEIGHBORS = "getneighbors"; + public final static String GET_NODES = "getnodes"; + public final static String GET_SHORTEST_PATH = "getshortestpath"; + public final static String GET_SUB_GRAPH = "getsubgraph"; + public final static String SUGGEST_LINKS = "suggestlinks"; + public final static String SUMMARIZE_GRAPH = "summarizegraph"; + + /* + public final static String CREATE_CLASSIFICATION_OBJECTS = "createclassificationobjects"; + public final static String CREATE_POLICY_OBJECTS = "createpolicyobjects"; + public final static String DELETE_CLASSIFICATION_OBJECTS = "deleteclassificationobjects"; + public final static String DELETE_POLICY_OBJECTS = "deletepolicyobjects"; + public final static String RETRIEVE_CLASSIFICATION_OBJECTS = "retrieveclassificationobjects"; + public final static String RETRIEVE_POLICY_OBJECTS = "retrievepolicyobjects"; + public final static String UPDATE_CLASSIFICATION_OBJECTS = "updateclassificationobjects"; + public final static String UPDATE_POLICY_OBJECTS = "updatepolicyobjects"; + */ + + public final static String PREDICT = "predict"; + public final static String RECOMMEND = "recommend"; + public final static String TRAIN_PREDICTOR = "trainpredictor"; + + public final static String CREATE_QUERY_PROFILE = "createqueryprofile"; + public final static String DELETE_QUERY_PROFILE = "deletequeryprofile"; + public final static String RETRIEVE_QUERY_PROFILE = "retrievequeryprofile"; + public final static String UPDATE_QUERY_PROFILE = "updatequeryprofile"; + + public final static String FIND_RELATED_CONCEPTS = "findrelatedconcepts"; + /* + public final static String FIND_SIMILAR = "findsimilar"; + public final static String GET_CONTENT = "getcontent"; + public final static String GET_PARAMETRIC_VALUES = "getparametricvalues"; + public final static String QUERY_TEXT_INDEX = "querytextindex"; + public final static String RETRIEVE_INDEX_FIELDS = "retrieveindexfields"; + */ + + public final static String AUTO_COMPLETE = "autocomplete"; + //public final static String CLASSIFY_DOCUMENT = "classifydocument"; + public final static String EXTRACT_CONCEPTS = "extractconcepts"; + //public final static String CATEGORIZE_DOCUMENT = "categorizedocument"; + //public final static String ENTITY_EXTRACTION = "extractentities"; + public final static String EXPAND_TERMS = "expandterms"; + public final static String HIGHLIGHT_TEXT = "highlighttext"; + public final static String IDENTIFY_LANGUAGE = "identifylanguage"; + public final static String ANALYZE_SENTIMENT = "analyzesentiment"; + public final static String TOKENIZE_TEXT = "tokenizetext"; + + public final static String ADD_TO_TEXT_INDEX = "addtotextindex"; + public final static String CREATE_TEXT_INDEX = "createtextindex"; + public final static String DELETE_TEXT_INDEX = "deletetextindex"; + public final static String DELETE_FROM_TEXT_INDEX = "deletefromtextindex"; + public final static String INDEX_STATUS = "indexstatus"; + //public final static String LIST_INDEXES = "listindexes"; REMOVED + public final static String LIST_RESOURCES = "listresources"; + public final static String RESTORE_TEXT_INDEX = "restoretextindex"; + +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/TextExtractionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/TextExtractionResponse.java new file mode 100644 index 0000000..db79582 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/TextExtractionResponse.java @@ -0,0 +1,40 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vuv on 9/24/2015. + */ +public class TextExtractionResponse { + public List document; // (array[object]) + + public class Object { + public String name; + public String reference; + public String parent_iod_reference; + public String doc_iod_reference; + public List content_type; + public List document_attributes; + public List keyview_class; + public List original_size; + public List keyview_type; + public List import_original_encoding; + public String content; + public Error error; + public List app_name; + public List author; + public List char_count; + public List code_page; + public List company; + public List created_date; + public List edit_time; + public List heading_pairs; + public List last_author; + public List last_printed; + public List modified_date; + } + public class Error { + public Integer error; + public String reason; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/TextTokenizationResponse.java b/hodresponseparser/src/main/java/hod/response/parser/TextTokenizationResponse.java new file mode 100644 index 0000000..07a1351 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/TextTokenizationResponse.java @@ -0,0 +1,23 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class TextTokenizationResponse { + public List terms; //(array[Terms] ) The details of the tokenized terms. + + public class Terms + { + //public double case; //( enum , optional) A value between indicating the term's case. + public int documents; //(number ) The number of documents that the specified term occurs in. + //public double length; //(number , optional) The length of the term in characters. + //public int numeric; //( enum , optional) A value indicating whether the term contains numbers. + public int occurrences; //(number ) The number of times the specified term occurs. + //public double start_pos; //(number , optional) The position in characters of the start of the word in the original text. + //public double stop_word; //( string , optional) This tag appears only if the term is a stop word. + public String term; //( string ) The term whose information is displayed. + public double weight; //( number ) The weight of the specified term. + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/TrainPredictionResponse.java b/hodresponseparser/src/main/java/hod/response/parser/TrainPredictionResponse.java new file mode 100644 index 0000000..5c0a1f1 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/TrainPredictionResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class TrainPredictionResponse { + public String message; //( string ) A message that contains the status of the service. + public String service; //( string ) The name that identifies the service that has been created. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/TrendAnalysisResponse.java b/hodresponseparser/src/main/java/hod/response/parser/TrendAnalysisResponse.java new file mode 100644 index 0000000..883f456 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/TrendAnalysisResponse.java @@ -0,0 +1,30 @@ +package hod.response.parser; + +import java.util.List; + +/** + * Created by vanphongvu on 3/29/16. + */ +public class TrendAnalysisResponse { + List trend_collections; + public class TrendCollection + { + List trends; + } + public class Trend + { + String trend; + Double measure_percentage_main_group; + Double measure_value_main_group; + String main_trend; + Double score; + Double measure_percentage_compared_group; + List measure; + List category; + } + class Category + { + String column; + String value; + } +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/UpdateConnectorResponse.java b/hodresponseparser/src/main/java/hod/response/parser/UpdateConnectorResponse.java new file mode 100644 index 0000000..0297048 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/UpdateConnectorResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class UpdateConnectorResponse { + public String connector; // The name of the connector. + public String message; // Indicates that the connector was updated. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/UpdateQueryProfileResponse.java b/hodresponseparser/src/main/java/hod/response/parser/UpdateQueryProfileResponse.java new file mode 100644 index 0000000..9a8aa49 --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/UpdateQueryProfileResponse.java @@ -0,0 +1,9 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class UpdateQueryProfileResponse { + public String message; //(string ) Indicates that the profile was updated. + public String query_profile; //(string ) Query profile name. +} diff --git a/hodresponseparser/src/main/java/hod/response/parser/ViewDocumentResponse.java b/hodresponseparser/src/main/java/hod/response/parser/ViewDocumentResponse.java new file mode 100644 index 0000000..0cc99af --- /dev/null +++ b/hodresponseparser/src/main/java/hod/response/parser/ViewDocumentResponse.java @@ -0,0 +1,8 @@ +package hod.response.parser; + +/** + * Created by vanphongvu on 12/7/15. + */ +public class ViewDocumentResponse { + public String document; // The Base 64 encoded HTML version of the document, if rawhtml is set to false. +} diff --git a/hodresponseparser/src/main/res/values/strings.xml b/hodresponseparser/src/main/res/values/strings.xml new file mode 100644 index 0000000..6a4fd3c --- /dev/null +++ b/hodresponseparser/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + hodresponseparser +