use of ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProfileList in project Saiy-PS by brandall76.
the class ListIDProfiles method getProfiles.
/**
* Method to get all enrollment profile information.
*
* @return an {@link Pair} of which the first parameter will denote success and the second an
* {@link ProfileList} object, containing the list of profiles. If the request was unsuccessful,
* the second parameter may be null.
*/
public Pair<Boolean, ProfileList> getProfiles() {
if (DEBUG) {
MyLog.i(CLS_NAME, "getProfiles");
}
final long then = System.nanoTime();
final RequestFuture<String> future = RequestFuture.newFuture();
final RequestQueue queue = Volley.newRequestQueue(mContext);
queue.start();
final StringRequest request = new StringRequest(Request.Method.GET, LIST_URL, future, new Response.ErrorListener() {
@Override
public void onErrorResponse(final VolleyError error) {
if (DEBUG) {
MyLog.w(CLS_NAME, "onErrorResponse: " + error.toString());
ListIDProfiles.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(OCP_SUBSCRIPTION_KEY_HEADER, apiKey);
return params;
}
};
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * OTT_MULTIPLIER, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(request);
String response = null;
try {
response = future.get(THREAD_TIMEOUT, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "getProfiles: InterruptedException");
e.printStackTrace();
}
} catch (final ExecutionException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "getProfiles: ExecutionException");
e.printStackTrace();
}
} catch (final TimeoutException e) {
if (DEBUG) {
MyLog.w(CLS_NAME, "getProfiles: TimeoutException");
e.printStackTrace();
}
} finally {
queue.stop();
}
if (DEBUG) {
MyLog.getElapsed(CLS_NAME, then);
}
if (response != null) {
if (DEBUG) {
MyLog.i(CLS_NAME, "response: " + response);
}
final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
final Type type = new TypeToken<List<ProfileItem>>() {
}.getType();
final ProfileList profileList = new ProfileList(gson.<List<ProfileItem>>fromJson(response, type));
if (DEBUG) {
MyLog.i(CLS_NAME, "onResponse: profileList size: " + profileList.getItems().size());
}
return new Pair<>(true, profileList);
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "response: failed");
}
return new Pair<>(false, null);
}
}
Aggregations