use of ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProcessingResult in project Saiy-PS by brandall76.
the class FetchIDOperation method getStatus.
/**
* Method to get an enrollment id.
*
* @return an {@link Pair} of which the first parameter will denote success and the second an
* {@link OperationStatus} object. If the request was unsuccessful,
* the second parameter may be null.
*/
public Pair<Boolean, OperationStatus> getStatus() {
if (DEBUG) {
MyLog.i(CLS_NAME, "getStatus");
}
final long then = System.nanoTime();
final RequestFuture<JSONObject> future = RequestFuture.newFuture();
final RequestQueue queue = Volley.newRequestQueue(mContext);
queue.start();
final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null, future, new Response.ErrorListener() {
@Override
public void onErrorResponse(final VolleyError error) {
if (DEBUG) {
MyLog.w(CLS_NAME, "onErrorResponse: " + error.toString());
FetchIDOperation.this.verboseError(error);
}
queue.stop();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
final Map<String, String> params = new HashMap<>();
params.put(CHARSET, ENCODING);
params.put(JSON_HEADER_ACCEPT, JSON_HEADER_VALUE_ACCEPT);
params.put(OCP_SUBSCRIPTION_KEY_HEADER, apiKey);
return params;
}
};
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(jsonObjReq);
JSONObject response = null;
try {
response = future.get(THREAD_TIMEOUT, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "getStatus: InterruptedException");
e.printStackTrace();
}
} catch (final ExecutionException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "getStatus: ExecutionException");
e.printStackTrace();
}
} catch (final TimeoutException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "getStatus: TimeoutException");
e.printStackTrace();
}
} finally {
queue.stop();
}
if (DEBUG) {
MyLog.getElapsed(CLS_NAME, then);
}
if (response != null) {
if (DEBUG) {
MyLog.i(CLS_NAME, "response: " + response.toString());
}
final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
final OperationStatus operationStatus = gson.fromJson(response.toString(), OperationStatus.class);
if (DEBUG) {
MyLog.i(CLS_NAME, "response: getStatus: " + operationStatus.getStatus());
MyLog.i(CLS_NAME, "response: getCreated: " + operationStatus.getCreated());
MyLog.i(CLS_NAME, "response: getLastAction: " + operationStatus.getLastAction());
MyLog.i(CLS_NAME, "response: getMessage: " + operationStatus.getMessage());
final ProcessingResult processingResult = operationStatus.getProcessingResult();
if (processingResult != null) {
MyLog.i(CLS_NAME, "response: getEnrollmentStatus: " + processingResult.getEnrollmentStatus());
MyLog.i(CLS_NAME, "response: getConfidence: " + processingResult.getConfidence());
MyLog.i(CLS_NAME, "response: getProfileId: " + processingResult.getProfileId());
MyLog.i(CLS_NAME, "response: getEnrollmentSpeechTime: " + processingResult.getEnrollmentSpeechTime());
MyLog.i(CLS_NAME, "response: getRemainingSpeechTime: " + processingResult.getRemainingSpeechTime());
MyLog.i(CLS_NAME, "response: getSpeechTime: " + processingResult.getSpeechTime());
} else {
MyLog.i(CLS_NAME, "response: processingResult: null");
}
}
return new Pair<>(true, operationStatus);
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "response: failed");
}
return new Pair<>(false, null);
}
}
Aggregations