From 850c267aa41b58b87f28696de5f79cd7b21f48f1 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Sun, 2 Jul 2017 08:26:45 +0800 Subject: [PATCH] updated web-api using callbacks --- web/src/net/irext/webapi/WebAPICallbacks.java | 90 ++++ web/src/net/irext/webapi/WebAPIs.java | 96 +++-- web/src/net/irext/webapi/model/Admin.java | 73 ---- web/src/net/irext/webapi/model/UserApp.java | 397 ++++++++++++++++++ .../irext/webapi/response/LoginResponse.java | 11 +- 5 files changed, 557 insertions(+), 110 deletions(-) create mode 100644 web/src/net/irext/webapi/WebAPICallbacks.java delete mode 100644 web/src/net/irext/webapi/model/Admin.java create mode 100644 web/src/net/irext/webapi/model/UserApp.java diff --git a/web/src/net/irext/webapi/WebAPICallbacks.java b/web/src/net/irext/webapi/WebAPICallbacks.java new file mode 100644 index 0000000..bdac629 --- /dev/null +++ b/web/src/net/irext/webapi/WebAPICallbacks.java @@ -0,0 +1,90 @@ +package net.irext.webapi; + +import net.irext.webapi.model.Brand; +import net.irext.webapi.model.Category; +import net.irext.webapi.model.City; +import net.irext.webapi.model.RemoteIndex; +import net.irext.webapi.model.StbOperator; +import net.irext.webapi.model.UserApp; + +import java.io.InputStream; +import java.util.List; + +/** + * Filename: WebAPICallbacks.java + * Revised: Date: 2017-07-01 + * Revision: Revision: 1.0 + *

+ * Description: HTTP Response Callbacks + *

+ * Revision log: + * 2017-07-01: created by strawmanbobi + */ +public class WebAPICallbacks { + + public interface SignInCallback { + void onSignInSuccess(UserApp admin); + void onSignInFailed(); + void onSignInError(); + } + + public interface ListCategoriesCallback { + void onListCategoriesSuccess(List categories); + void onListCategoriesFailed(); + void onListCategoriesError(); + } + + public interface ListBrandsCallback { + void onListBrandsSuccess(List brands); + void onListBrandsFailed(); + void onListBrandsError(); + } + + public interface ListPopularBrandsCallback { + void onListPopularBrandsSuccess(List brands); + void onListPopularBrandsFailed(); + void onListPopularBrandsError(); + } + + public interface ListPopularCitiesCallback { + void onListPopularCitiesSuccess(List cities); + void onListPopularCitiesFailed(); + void onListPopularCitiesError(); + } + + public interface ListProvincesCallback { + void onListProvincesSuccess(List provinces); + void onListProvincesFailed(); + void onListProvincesError(); + } + + public interface ListCitiesCallback { + void onListCitiesSuccess(List cities); + void onListCitiesFailed(); + void onListCitiesError(); + } + + public interface ListAreasCallback { + void onListAreasSuccess(List cities); + void onListAreasFailed(); + void onListAreasError(); + } + + public interface ListOperatersCallback { + void onListOperatorsSuccess(List operators); + void onListOperatorsFailed(); + void onListOperatorsError(); + } + + public interface ListIndexesCallback { + void onListIndexesSuccess(List indexes); + void onListIndexesFailed(); + void onListIndexesError(); + } + + public interface DownloadBinCallback { + void onDownloadBinSuccess(InputStream inputStream); + void onDownloadBinFailed(); + void onDownloadBinError(); + } +} diff --git a/web/src/net/irext/webapi/WebAPIs.java b/web/src/net/irext/webapi/WebAPIs.java index 727e777..b9f5b01 100644 --- a/web/src/net/irext/webapi/WebAPIs.java +++ b/web/src/net/irext/webapi/WebAPIs.java @@ -5,11 +5,11 @@ import net.irext.webapi.model.*; import net.irext.webapi.utils.Constants; import net.irext.webapi.request.*; import net.irext.webapi.response.*; +import net.irext.webapi.WebAPICallbacks.*; import okhttp3.*; import java.io.IOException; import java.io.InputStream; -import java.util.List; /** * Filename: WebAPIs.java @@ -94,7 +94,7 @@ public class WebAPIs { } @SuppressWarnings("unused") - public Admin signIn(String appKey, String appSecret) { + public void signIn(String appKey, String appSecret, SignInCallback signInCallback) { String signInURL = URL_PREFIX + SERVICE_SIGN_IN; AppSignInRequest appSignInRequest = new AppSignInRequest(); appSignInRequest.setAppKey(appKey); @@ -106,21 +106,23 @@ public class WebAPIs { String response = postToServer(signInURL, bodyJson); LoginResponse loginResponse = new Gson().fromJson(response, LoginResponse.class); if(loginResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { - Admin admin = loginResponse.getEntity(); + UserApp admin = loginResponse.getEntity(); if (0 != admin.getId() && null != admin.getToken()) { adminId = admin.getId(); token = admin.getToken(); + signInCallback.onSignInSuccess(admin); + } else { + signInCallback.onSignInFailed(); } - return admin; } } catch (Exception e) { e.printStackTrace(); + signInCallback.onSignInError(); } - return null; } @SuppressWarnings("unused") - public List listCategories(int from, int count) { + public void listCategories(int from, int count, ListCategoriesCallback listCategoriesCallback) { String listCategoriesURL = URL_PREFIX + SERVICE_LIST_CATEGORIES; ListCategoriesRequest listCategoriesRequest = new ListCategoriesRequest(); listCategoriesRequest.setAdminId(adminId); @@ -134,16 +136,19 @@ public class WebAPIs { CategoriesResponse categoriesResponse = new Gson().fromJson(response, CategoriesResponse.class); if(categoriesResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { - return categoriesResponse.getEntity(); + listCategoriesCallback.onListCategoriesSuccess(categoriesResponse.getEntity()); + } else { + listCategoriesCallback.onListCategoriesFailed(); } } catch (Exception e) { e.printStackTrace(); + listCategoriesCallback.onListCategoriesError(); } - return null; } @SuppressWarnings("unused") - public List listBrands(int categoryId, int from, int count) { + public void listBrands(int categoryId, int from, int count, + ListBrandsCallback listBrandsCallback) { String listBrandsURL = URL_PREFIX + SERVICE_LIST_BRANDS; ListBrandsRequest listBrandsRequest = new ListBrandsRequest(); listBrandsRequest.setAdminId(adminId); @@ -157,28 +162,42 @@ public class WebAPIs { String response = postToServer(listBrandsURL, bodyJson); BrandsResponse brandsResponse = new Gson().fromJson(response, BrandsResponse.class); - if(brandsResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { - return brandsResponse.getEntity(); + if (brandsResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { + listBrandsCallback.onListBrandsSuccess(brandsResponse.getEntity()); + } else { + listBrandsCallback.onListBrandsFailed(); } } catch (Exception e) { e.printStackTrace(); + listBrandsCallback.onListBrandsError(); } - return null; } @SuppressWarnings("unused") - public List listProvinces() { + public void listProvinces(ListProvincesCallback listProvincesCallback) { String listProvincesURL = URL_PREFIX + SERVICE_LIST_PROVINCES; ListCitiesRequest listCitiesRequest = new ListCitiesRequest(); listCitiesRequest.setAdminId(adminId); listCitiesRequest.setToken(token); String bodyJson = listCitiesRequest.toJson(); - return listCitiesCommon(listProvincesURL, bodyJson); + try { + String response = postToServer(listProvincesURL, bodyJson); + CitiesResponse citiesResponse = new Gson().fromJson(response, CitiesResponse.class); + + if (citiesResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { + listProvincesCallback.onListProvincesSuccess(citiesResponse.getEntity()); + } else { + listProvincesCallback.onListProvincesFailed(); + } + } catch (Exception e) { + e.printStackTrace(); + listProvincesCallback.onListProvincesError(); + } } @SuppressWarnings("unused") - public List listCities(String prefix) { + public void listCities(String prefix, ListCitiesCallback listCitiesCallback) { String listCitiesURL = URL_PREFIX + SERVICE_LIST_CITIES; ListCitiesRequest listCitiesRequest = new ListCitiesRequest(); listCitiesRequest.setAdminId(adminId); @@ -186,25 +205,24 @@ public class WebAPIs { listCitiesRequest.setProvincePrefix(prefix); String bodyJson = listCitiesRequest.toJson(); - return listCitiesCommon(listCitiesURL, bodyJson); - } - - private List listCitiesCommon(String url, String bodyJson) { try { - String response = postToServer(url, bodyJson); + String response = postToServer(listCitiesURL, bodyJson); CitiesResponse citiesResponse = new Gson().fromJson(response, CitiesResponse.class); if (citiesResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { - return citiesResponse.getEntity(); + listCitiesCallback.onListCitiesSuccess(citiesResponse.getEntity()); + } else { + listCitiesCallback.onListCitiesFailed(); } } catch (Exception e) { e.printStackTrace(); + listCitiesCallback.onListCitiesError(); } - return null; } @SuppressWarnings("unused") - public List listOperators(String cityCode) { + public void listOperators(String cityCode, + ListOperatersCallback listOperatersCallback) { String listOperatorsURL = URL_PREFIX + SERVICE_LIST_OPERATORS; ListOperatorsRequest listOperatorsRequest = new ListOperatorsRequest(); listOperatorsRequest.setAdminId(adminId); @@ -219,16 +237,22 @@ public class WebAPIs { OperatorsResponse operatorsResponse = new Gson().fromJson(response, OperatorsResponse.class); if (operatorsResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { - return operatorsResponse.getEntity(); + listOperatersCallback.onListOperatorsSuccess(operatorsResponse.getEntity()); + } else { + listOperatersCallback.onListOperatorsFailed(); } } catch (Exception e) { e.printStackTrace(); + listOperatersCallback.onListOperatorsError(); } - return null; } @SuppressWarnings("unused") - public List listRemoteIndexes(int categoryId, int brandId, String cityCode, String operatorId) { + public void listRemoteIndexes(int categoryId, + int brandId, + String cityCode, + String operatorId, + ListIndexesCallback onListIndexCallback) { String listIndexesURL = URL_PREFIX + SERVICE_LIST_INDEXES; ListIndexesRequest listIndexesRequest = new ListIndexesRequest(); listIndexesRequest.setAdminId(adminId); @@ -247,16 +271,19 @@ public class WebAPIs { IndexesResponse indexesResponse = new Gson().fromJson(response, IndexesResponse.class); if (indexesResponse.getStatus().getCode() == Constants.ERROR_CODE_SUCCESS) { - return indexesResponse.getEntity(); + onListIndexCallback.onListIndexesSuccess(indexesResponse.getEntity()); + } else { + onListIndexCallback.onListIndexesFailed(); } } catch (Exception e) { e.printStackTrace(); + onListIndexCallback.onListIndexesError(); } - return null; } @SuppressWarnings("unused") - public InputStream downloadBin(String remoteMap, int indexId) { + public void downloadBin(String remoteMap, int indexId, + DownloadBinCallback downloadBinCallback) { String downloadURL = URL_PREFIX + SERVICE_DOWNLOAD_BIN; DownloadBinaryRequest downloadBinaryRequest = new DownloadBinaryRequest(); downloadBinaryRequest.setAdminId(adminId); @@ -267,15 +294,22 @@ public class WebAPIs { if (null != bodyJson) { try { - return postToServerForOctets(downloadURL, bodyJson); + InputStream binStream = postToServerForOctets(downloadURL, bodyJson); + + if (null != binStream) { + downloadBinCallback.onDownloadBinSuccess(binStream); + } else { + downloadBinCallback.onDownloadBinFailed(); + } } catch (IOException e) { e.printStackTrace(); + downloadBinCallback.onDownloadBinError(); } } - return null; } @SuppressWarnings("unused") + @Deprecated public int[] decodeIR(int indexId) { String decodeURL = URL_PREFIX + SERVICE_ONLINE_DECODE; DecodeRequest decodeRequest = new DecodeRequest(); diff --git a/web/src/net/irext/webapi/model/Admin.java b/web/src/net/irext/webapi/model/Admin.java deleted file mode 100644 index 7dc5d5a..0000000 --- a/web/src/net/irext/webapi/model/Admin.java +++ /dev/null @@ -1,73 +0,0 @@ -package net.irext.webapi.model; - -/** - * Filename: Admin.java - * Revised: Date: 2017-04-01 - * Revision: Revision: 1.0 - *

- * Description: Admin bean - *

- * Revision log: - * 2017-04-01: created by strawmanbobi - */ -public class Admin { - - private int id; - private String userName; - private String password; - private String token; - private String permissions; - private int adminType; - - public Admin() { - - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public String getPermissions() { - return permissions; - } - - public void setPermissions(String permissions) { - this.permissions = permissions; - } - - public int getAdminType() { - return adminType; - } - - public void setAdminType(int adminType) { - this.adminType = adminType; - } -} diff --git a/web/src/net/irext/webapi/model/UserApp.java b/web/src/net/irext/webapi/model/UserApp.java new file mode 100644 index 0000000..e16c502 --- /dev/null +++ b/web/src/net/irext/webapi/model/UserApp.java @@ -0,0 +1,397 @@ +package net.irext.webapi.model; + +public class UserApp { + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.id + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private Integer id; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.app_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String appName; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.admin_id + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private Integer adminId; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.admin_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String adminName; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.app_type + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private Byte appType; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.android_package_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String androidPackageName; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.android_signature + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String androidSignature; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.ios_identity + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String iosIdentity; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.is_debug + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private Byte isDebug; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.app_key + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String appKey; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.app_secret + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String appSecret; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column user_app.update_time + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + private String updateTime; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.id + * + * @return the value of user_app.id + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public Integer getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.id + * + * @param id the value for user_app.id + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.app_name + * + * @return the value of user_app.app_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getAppName() { + return appName; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.app_name + * + * @param appName the value for user_app.app_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAppName(String appName) { + this.appName = appName; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.admin_id + * + * @return the value of user_app.admin_id + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public Integer getAdminId() { + return adminId; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.admin_id + * + * @param adminId the value for user_app.admin_id + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAdminId(Integer adminId) { + this.adminId = adminId; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.admin_name + * + * @return the value of user_app.admin_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getAdminName() { + return adminName; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.admin_name + * + * @param adminName the value for user_app.admin_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAdminName(String adminName) { + this.adminName = adminName; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.app_type + * + * @return the value of user_app.app_type + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public Byte getAppType() { + return appType; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.app_type + * + * @param appType the value for user_app.app_type + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAppType(Byte appType) { + this.appType = appType; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.android_package_name + * + * @return the value of user_app.android_package_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getAndroidPackageName() { + return androidPackageName; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.android_package_name + * + * @param androidPackageName the value for user_app.android_package_name + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAndroidPackageName(String androidPackageName) { + this.androidPackageName = androidPackageName; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.android_signature + * + * @return the value of user_app.android_signature + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getAndroidSignature() { + return androidSignature; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.android_signature + * + * @param androidSignature the value for user_app.android_signature + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAndroidSignature(String androidSignature) { + this.androidSignature = androidSignature; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.ios_identity + * + * @return the value of user_app.ios_identity + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getIosIdentity() { + return iosIdentity; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.ios_identity + * + * @param iosIdentity the value for user_app.ios_identity + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setIosIdentity(String iosIdentity) { + this.iosIdentity = iosIdentity; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.is_debug + * + * @return the value of user_app.is_debug + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public Byte getIsDebug() { + return isDebug; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.is_debug + * + * @param isDebug the value for user_app.is_debug + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setIsDebug(Byte isDebug) { + this.isDebug = isDebug; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.app_key + * + * @return the value of user_app.app_key + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getAppKey() { + return appKey; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.app_key + * + * @param appKey the value for user_app.app_key + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAppKey(String appKey) { + this.appKey = appKey; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.app_secret + * + * @return the value of user_app.app_secret + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getAppSecret() { + return appSecret; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.app_secret + * + * @param appSecret the value for user_app.app_secret + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setAppSecret(String appSecret) { + this.appSecret = appSecret; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column user_app.update_time + * + * @return the value of user_app.update_time + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public String getUpdateTime() { + return updateTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column user_app.update_time + * + * @param updateTime the value for user_app.update_time + * + * @mbggenerated Fri May 26 19:47:48 CST 2017 + */ + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } + + private String token; + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } +} \ No newline at end of file diff --git a/web/src/net/irext/webapi/response/LoginResponse.java b/web/src/net/irext/webapi/response/LoginResponse.java index f97221a..eb2d8ca 100644 --- a/web/src/net/irext/webapi/response/LoginResponse.java +++ b/web/src/net/irext/webapi/response/LoginResponse.java @@ -1,7 +1,6 @@ package net.irext.webapi.response; -import net.irext.webapi.model.Admin; - +import net.irext.webapi.model.UserApp; /** * Filename: LoginResponse.java * Revised: Date: 2017-03-31 @@ -14,9 +13,9 @@ import net.irext.webapi.model.Admin; */ public class LoginResponse extends ServiceResponse { - private Admin entity; + private UserApp entity; - public LoginResponse(Status status, Admin admin) { + public LoginResponse(Status status, UserApp admin) { super(status); this.entity = admin; } @@ -25,11 +24,11 @@ public class LoginResponse extends ServiceResponse { } - public Admin getEntity() { + public UserApp getEntity() { return entity; } - public void setEntity(Admin entity) { + public void setEntity(UserApp entity) { this.entity = entity; } }