Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jcenter #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
610 changes: 501 additions & 109 deletions README.md

Large diffs are not rendered by default.

38 changes: 36 additions & 2 deletions hodclient/build.gradle
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'

licenseName = 'MIT license'
licenseUrl = ''
allLicenses = ["MIT"]
}

android {
compileSdkVersion 20
Expand All @@ -7,19 +30,30 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 20
versionCode 1
versionName "1.0"
versionCode 3
versionName "2.1"
}
buildTypes {
release {
minifyEnabled false
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 {
compile fileTree(dir: 'libs', include: ['*.jar'])
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'
5 changes: 4 additions & 1 deletion hodclient/hodclient.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":hodclient" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="IODClientDemo" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":hodclient" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.havenondemand" external.system.module.version="2.1" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -65,6 +65,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -84,7 +85,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
Expand Down
4 changes: 4 additions & 0 deletions hodclient/src/main/java/hod/api/hodclient/HODApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
169 changes: 97 additions & 72 deletions hodclient/src/main/java/hod/api/hodclient/HODClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -32,18 +34,17 @@
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;
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;
Expand All @@ -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();
Expand All @@ -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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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)
Expand All @@ -135,36 +135,36 @@ class MakeAsyncActivitiesTask extends AsyncTask<Object, String, String> {
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<String, Object> map = (Map) params[0];
for (Map.Entry<String, Object> e : map.entrySet()) {
String key = e.getKey();
if (key.equals("arrays")) {
Map<String, String> submap = (Map) e.getValue();
for (Map.Entry<String, String> 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<String>) 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();
}
}
Expand All @@ -190,26 +190,51 @@ else if (httpMethod == HTTP_METHOD.POST) {
reqEntity.addPart("apikey", new StringBody(apiKey, ContentType.TEXT_PLAIN));
for (Map.Entry<String, Object> 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<String,String> submap = (Map)e.getValue();
for (Map.Entry<String, String> 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<String>) 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<String>) 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());
Expand Down Expand Up @@ -247,6 +272,7 @@ else if (httpMethod == HTTP_METHOD.POST) {
isError = true;
return e.getMessage();
}
//return null;
}

@Override
Expand All @@ -256,7 +282,6 @@ protected void onProgressUpdate(String... unsued) {

@Override
protected void onPostExecute(String sResponse) {
isBusy = false;
if (isError) {
ParseError(sResponse);
} else {
Expand All @@ -270,4 +295,4 @@ private static String getMimeType(String url) {
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap);
return mimeType;
}
}
}
1 change: 1 addition & 0 deletions hodresponseparser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading