Commit 7ae70cfd by Kunj Gupta

For each API call create different interface.

parent 39d51751
package com.vsoft.uofl_catalogue.api.interfaces;
import com.vsoft.uofl_catalogue.utils.Constants;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
/**
* @since 1.0
* @author Kunj on 11/8/16.
*
*/
public interface CatalogueCategoryApi {
// Get Catalogue API
@GET(Constants.URL_GET_CATALOGUE)
Call<ResponseBody> getCatalogue(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery,
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields);
}
package com.vsoft.uofl_catalogue.api.interfaces;
import com.vsoft.uofl_catalogue.utils.Constants;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
/**
* @since 1.0
* @author Kunj on 11/8/16.
*
*/
public interface CatalogueCategoryItemApi {
// Get Catalogue Item API
@GET(Constants.URL_GET_CATALOGUE_ITEM)
Call<ResponseBody> getCatalogueItem(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery,
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields);
}
...@@ -19,17 +19,7 @@ import retrofit2.http.Url; ...@@ -19,17 +19,7 @@ import retrofit2.http.Url;
* @author Kunj on 11/8/16. * @author Kunj on 11/8/16.
* *
*/ */
public interface CatalogueApi { public interface CatalogueVariableApi {
// Get Catalogue API
@GET(Constants.URL_GET_CATALOGUE)
Call<ResponseBody> getCatalogue(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery,
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields);
// Get Catalogue Item API
@GET(Constants.URL_GET_CATALOGUE_ITEM)
Call<ResponseBody> getCatalogueItem(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery,
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields);
// Get Variable API // Get Variable API
@GET(Constants.URL_GET_VARIABLE) @GET(Constants.URL_GET_VARIABLE)
Call<ResponseBody> getVariable(@Query(CatalogueVariable.Json.SYS_ID) String sysId); Call<ResponseBody> getVariable(@Query(CatalogueVariable.Json.SYS_ID) String sysId);
...@@ -47,7 +37,6 @@ public interface CatalogueApi { ...@@ -47,7 +37,6 @@ public interface CatalogueApi {
// Get Reference API // Get Reference API
@GET @GET
Call<ResponseBody> getReference(@Url String url, @Query(Reference.Json.FIRST_NAME) String firstName); Call<ResponseBody> getReference(@Url String url, @Query(Reference.Json.FIRST_NAME) String firstName);
} }
...@@ -7,8 +7,8 @@ import com.google.gson.JsonDeserializer; ...@@ -7,8 +7,8 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uofl_catalogue.api.RestClient; import com.vsoft.uofl_catalogue.api.RestClient;
import com.vsoft.uofl_catalogue.api.interfaces.CatalogueCategoryApi;
import com.vsoft.uofl_catalogue.db.models.Catalogue; import com.vsoft.uofl_catalogue.db.models.Catalogue;
import com.vsoft.uofl_catalogue.api.interfaces.CatalogueApi;
import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueApiListener;
import com.vsoft.uofl_catalogue.enums.SyncStatus; import com.vsoft.uofl_catalogue.enums.SyncStatus;
import com.vsoft.uofl_catalogue.utils.CatalogueLog; import com.vsoft.uofl_catalogue.utils.CatalogueLog;
...@@ -43,7 +43,7 @@ public class CatalogueApiManager { ...@@ -43,7 +43,7 @@ public class CatalogueApiManager {
CatalogueLog.d("CatalogueApiManager: getCatalogues: request parameter: "+stringBuilder.toString()); CatalogueLog.d("CatalogueApiManager: getCatalogues: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueApi.class).getCatalogue(stringBuilder.toString(), "sys_id,title,description"); Call<ResponseBody> call = retrofit.create(CatalogueCategoryApi.class).getCatalogue(stringBuilder.toString(), "sys_id,title,description");
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
......
...@@ -7,7 +7,7 @@ import com.google.gson.JsonDeserializer; ...@@ -7,7 +7,7 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uofl_catalogue.api.RestClient; import com.vsoft.uofl_catalogue.api.RestClient;
import com.vsoft.uofl_catalogue.api.interfaces.CatalogueApi; import com.vsoft.uofl_catalogue.api.interfaces.CatalogueCategoryItemApi;
import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueItemApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueItemApiListener;
import com.vsoft.uofl_catalogue.db.models.CatalogueItem; import com.vsoft.uofl_catalogue.db.models.CatalogueItem;
import com.vsoft.uofl_catalogue.enums.SyncStatus; import com.vsoft.uofl_catalogue.enums.SyncStatus;
...@@ -43,7 +43,7 @@ public class CatalogueItemApiManager { ...@@ -43,7 +43,7 @@ public class CatalogueItemApiManager {
CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: request parameter: "+stringBuilder.toString()); CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueApi.class).getCatalogueItem(stringBuilder.toString(), "sys_id,short_description,name,description"); Call<ResponseBody> call = retrofit.create(CatalogueCategoryItemApi.class).getCatalogueItem(stringBuilder.toString(), "sys_id,short_description,name,description");
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -125,26 +125,4 @@ public class CatalogueItemApiManager { ...@@ -125,26 +125,4 @@ public class CatalogueItemApiManager {
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} }
public static SyncStatus submitCatalogueItem(String catalogueItemSysId, JSONArray catalogueJsonArray) {
CatalogueLog.d("submitCatalogueItem: " + catalogueJsonArray);
String expenseJsonString = catalogueJsonArray.toString();
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueApi.class).postCatalogueItem(catalogueItemSysId, expenseJsonString);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
return SyncStatus.SUCCESS;
} else {
return SyncStatus.FAIL;
}
} catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: submitCatalogueItem: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e){
CatalogueLog.e("CatalogueItemApiManager: submitCatalogueItem: IOException: ", e);
return SyncStatus.FAIL;
}
}
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ import com.google.gson.JsonDeserializer; ...@@ -7,7 +7,7 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uofl_catalogue.api.RestClient; import com.vsoft.uofl_catalogue.api.RestClient;
import com.vsoft.uofl_catalogue.api.interfaces.CatalogueApi; import com.vsoft.uofl_catalogue.api.interfaces.CatalogueVariableApi;
import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueVariableApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.uofl_catalogue.db.models.CatalogueVariable; import com.vsoft.uofl_catalogue.db.models.CatalogueVariable;
import com.vsoft.uofl_catalogue.enums.SyncStatus; import com.vsoft.uofl_catalogue.enums.SyncStatus;
...@@ -37,7 +37,7 @@ public class CatalogueVariableApiManager { ...@@ -37,7 +37,7 @@ public class CatalogueVariableApiManager {
public static SyncStatus getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) { public static SyncStatus getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: "); CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueApi.class).getVariable(catalogueItemSysId); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariable(catalogueItemSysId);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -121,4 +121,26 @@ public class CatalogueVariableApiManager { ...@@ -121,4 +121,26 @@ public class CatalogueVariableApiManager {
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} }
public static SyncStatus submitVariableForm(String catalogueItemSysId, JSONArray catalogueJsonArray) {
CatalogueLog.d("submitVariableForm: " + catalogueJsonArray);
String expenseJsonString = catalogueJsonArray.toString();
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postCatalogueItem(catalogueItemSysId, expenseJsonString);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
return SyncStatus.SUCCESS;
} else {
return SyncStatus.FAIL;
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e){
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
}
}
} }
\ No newline at end of file
...@@ -29,10 +29,10 @@ public class LoginApiManger { ...@@ -29,10 +29,10 @@ public class LoginApiManger {
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: submitCatalogueItem: IOException: ", e); CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL; return SyncStatus.FAIL;
} catch (NullPointerException e) { } catch (NullPointerException e) {
CatalogueLog.e("CatalogueItemApiManager: submitCatalogueItem: IOException: ", e); CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} }
......
...@@ -7,7 +7,7 @@ import com.google.gson.JsonDeserializer; ...@@ -7,7 +7,7 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uofl_catalogue.api.RestClient; import com.vsoft.uofl_catalogue.api.RestClient;
import com.vsoft.uofl_catalogue.api.interfaces.CatalogueApi; import com.vsoft.uofl_catalogue.api.interfaces.CatalogueVariableApi;
import com.vsoft.uofl_catalogue.api.listeners.get.GetReferenceApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetReferenceApiListener;
import com.vsoft.uofl_catalogue.api.listeners.get.GetVariableChoiceApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetVariableChoiceApiListener;
import com.vsoft.uofl_catalogue.db.models.Reference; import com.vsoft.uofl_catalogue.db.models.Reference;
...@@ -45,7 +45,7 @@ public class VariableChoiceApiManager { ...@@ -45,7 +45,7 @@ public class VariableChoiceApiManager {
CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: request parameter: "+stringBuilder.toString()); CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueApi.class).getVariableChoice(stringBuilder.toString(), "text,value,order,misc"); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariableChoice(stringBuilder.toString(), "text,value,order,misc");
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -132,7 +132,7 @@ public class VariableChoiceApiManager { ...@@ -132,7 +132,7 @@ public class VariableChoiceApiManager {
CatalogueLog.d("VariableChoiceApiManager: getReference: tableName: "+tableName); CatalogueLog.d("VariableChoiceApiManager: getReference: tableName: "+tableName);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueApi.class).getReference(Constants.URL_GET_REFERENCE + tableName, firstName); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getReference(Constants.URL_GET_REFERENCE + tableName, firstName);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
......
...@@ -28,7 +28,6 @@ import com.vsoft.uofl_catalogue.CatalogueApplication; ...@@ -28,7 +28,6 @@ import com.vsoft.uofl_catalogue.CatalogueApplication;
import com.vsoft.uofl_catalogue.R; import com.vsoft.uofl_catalogue.R;
import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueVariableApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.uofl_catalogue.api.listeners.get.GetVariableChoiceApiListener; import com.vsoft.uofl_catalogue.api.listeners.get.GetVariableChoiceApiListener;
import com.vsoft.uofl_catalogue.api.managers.CatalogueItemApiManager;
import com.vsoft.uofl_catalogue.api.managers.CatalogueVariableApiManager; import com.vsoft.uofl_catalogue.api.managers.CatalogueVariableApiManager;
import com.vsoft.uofl_catalogue.api.managers.VariableChoiceApiManager; import com.vsoft.uofl_catalogue.api.managers.VariableChoiceApiManager;
import com.vsoft.uofl_catalogue.db.models.CatalogueVariable; import com.vsoft.uofl_catalogue.db.models.CatalogueVariable;
...@@ -463,7 +462,7 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -463,7 +462,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
SyncStatus syncStatus = CatalogueItemApiManager.submitCatalogueItem(mCatalogueItemSysId, mJsonArray); SyncStatus syncStatus = CatalogueVariableApiManager.submitVariableForm(mCatalogueItemSysId, mJsonArray);
return syncStatus; return syncStatus;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment