To work with transactions, create the IdTransactionActivity application, which uses the methods implemented in the IdTransactionApi unit.
The application can be used to get responses to repeated requests on disconnection using transaction ID and without addressing the data source.
NOTE. Use sending of transaction data if caching is not set up.
For details about transaction ID see the Sending Transaction Data section.
The IdTransactionActivity application includes one screen, text input area and buttons:
GetAllTransaction. Get a transactions list.
GetRequest. Send a standard request.
RequestWithUUID. Send request containing UUID.
RetryRequest. Send request by UUID.
DeleteTransaction. Delete transaction by UUID.
The text input area contains UUID 00000000-0000-0000-0000-000000000001 by default.
To view application work results, use the interactive example:
Click the GetAllTransaction button.
public class IdTransactionActivity extends AppCompatActivity {
private static final String MY_URL = "http://testmasterfmp.fsight.cloud/";
private static final VersionAPI MY_VERSION_API = VersionAPI.V_1;
private static final String MY_ENVIRONMENT = "Leonid_environment";
private static final String MY_PROJECT = "Leonid_project";
private static final String MY_VERSION = "v1";
private static final String MY_LOGIN = "Leonid";
private static final String MY_PASSWORD = "123123";
private static final String MY_RESOURCE = "GetBudgetPlanning";
private static final String TAG = "TableStreamActivity";
private HyperHive hyperHive;
private TextView textView;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_id_transaction);
textView = findViewById(R.id.text_view_id_transaction);
editText = findViewById(R.id.edit_text_id_transaction);
editText.setText("00000000-0000-0000-0000-000000000001");
Handler uiHandler = new Handler();
hyperHive = new HyperHiveState(getApplicationContext())
.setHostWithSchema(MY_URL)
.setApiVersion(MY_VERSION_API)
.setEnvironmentSlug(MY_ENVIRONMENT)
.setProjectSlug(MY_PROJECT)
.setVersionProject(MY_VERSION)
.setHandler(uiHandler)
.buildHyperHive();
authentication();
}
public void authentication() {
boolean status = hyperHive.authAPI.auth(MY_LOGIN, MY_PASSWORD, true).execute().isOk();
showStatus(status);
}
public void showStatus(boolean status) {
Log.d(TAG, "auth: " + status);
Toast.makeText(this, "auth: " + status, Toast.LENGTH_LONG).show();
}
// Get transactions list
public void getAllTransaction(View view) {
RootClass.Result list = hyperHive.idTransactionApi.getAllTransaction(MY_RESOURCE, RootClass.class).execute().resultClass;
textView.setText(list.toString());
}
// Send standard request
public void getRequest(View view) {
RequestCallParams requestCallParams = new RequestCallParams();
String response = hyperHive.requestAPI.request(MY_RESOURCE, requestCallParams).execute();
textView.setText(response);
}
// Send request marked with uuid
public void getRequestWithUuid(View view) {
String uuid = editText.getText().toString();
RequestCallParams requestCallParams = new RequestCallParams();
requestCallParams.setTransactionID(uuid);
String response = hyperHive.requestAPI.request(MY_RESOURCE, requestCallParams).execute();
textView.setText(response);
}
// Get transaction data
public void retryRequest(View view) {
String uuid = editText.getText().toString();
RequestCallParams requestCallParams = new RequestCallParams();
requestCallParams.setTransactionID(uuid);
String response = hyperHive.requestAPI.retryRequest(MY_RESOURCE, requestCallParams).execute();
textView.setText(response);
}
// Delete specific transaction
public void deleteTransaction(View view) {
String uuid = editText.getText().toString();
boolean status = hyperHive.idTransactionApi.deleteTransaction(MY_RESOURCE, uuid).execute().isOk();
showStatus(status);
}
private class RootClass extends BaseStatus {
@Expose
@SerializedName("result")
public Result resultClass;
private class Result {
@Expose
@SerializedName("raw")
public List<Raw> rawList;
private class Raw {
@Expose
@SerializedName("uuid")
public String uuid;
}
@Override
public String toString() {
String str = "";
for (Raw raw : rawList) {
str += raw.uuid + "\n";
}
return str;
}
}
}
}
See also: