use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class ServerAPIController method pullUserAttributes.
public static User pullUserAttributes(User loggedUser) throws ApiCallException {
String lastMessage = loggedUser.getAnnouncement();
String uid = loggedUser.getUid();
String url = PreferencesState.getInstance().getDhisURL() + "/api/" + TAG_USER + String.format(QUERY_USER_ATTRIBUTES, uid);
url = ServerApiUtils.encodeBlanks(url);
Response response = ServerApiCallExecution.executeCall(null, url, "GET");
JSONObject body = ServerApiUtils.getApiResponseAsJSONObject(response);
JsonNode jsonNode = ServerApiUtils.getJsonNodeMappedResponse(body);
JsonNode jsonNodeArray = jsonNode.get(ATTRIBUTE_VALUES);
String newMessage = "";
String closeDate = "";
for (int i = 0; i < jsonNodeArray.size(); i++) {
if (jsonNodeArray.get(i).get(ATTRIBUTE).get(CODE).textValue().equals(User.ATTRIBUTE_USER_ANNOUNCEMENT)) {
newMessage = jsonNodeArray.get(i).get(VALUE).textValue();
}
if (jsonNodeArray.get(i).get(ATTRIBUTE).get(CODE).textValue().equals(User.ATTRIBUTE_USER_CLOSE_DATE)) {
closeDate = jsonNodeArray.get(i).get(VALUE).textValue();
}
}
if ((lastMessage == null && newMessage != null) || (newMessage != null && !newMessage.equals("") && !lastMessage.equals(newMessage))) {
loggedUser.setAnnouncement(newMessage);
PreferencesState.getInstance().setUserAccept(false);
}
if (closeDate == null || closeDate.equals("")) {
loggedUser.setCloseDate(null);
} else {
loggedUser.setCloseDate(Utils.parseStringToCalendar(closeDate, DHIS2_GMT_NEW_DATE_FORMAT).getTime());
}
loggedUser.save();
return loggedUser;
}
use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class ServerAPIController method patchDescriptionClosedDate.
static void patchDescriptionClosedDate(String url, String orgUnitUID, String orgUnitDescription) throws ApiCallException {
// https://malariacare.psi.org/api/organisationUnits/u5jlxuod8xQ/closedDate
try {
String urlPathClosedDescription = getPatchClosedDescriptionUrl(url, orgUnitUID);
JSONObject data = prepareClosingDescriptionValue(orgUnitDescription);
Response response = ServerApiCallExecution.executeCall(data, urlPathClosedDescription, "PATCH");
ServerApiUtils.checkResponse(response, null);
} catch (JSONException e) {
throw new ApiCallException(e);
}
}
use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class ServerAPIController method isUserClosed.
public static boolean isUserClosed(String userUid) throws ApiCallException {
if (Session.getCredentials().isDemoCredentials()) {
return false;
}
// Lets for a last event with that orgunit/program
String url = PreferencesState.getInstance().getDhisURL() + "/api/" + TAG_USER + String.format(QUERY_USER_ATTRIBUTES, userUid);
url = ServerApiUtils.encodeBlanks(url);
Date closedDate = null;
Response response = ServerApiCallExecution.executeCall(null, url, "GET");
JsonNode jsonNode = ServerApiUtils.getJsonNodeMappedResponse(ServerApiUtils.getApiResponseAsJSONObject(response));
JsonNode jsonNodeArray = jsonNode.get(ATTRIBUTEVALUES);
String closeDateAsString = "";
for (int i = 0; i < jsonNodeArray.size(); i++) {
if (jsonNodeArray.get(i).get(ATTRIBUTE).get(CODE).textValue().equals(User.ATTRIBUTE_USER_CLOSE_DATE)) {
closeDateAsString = jsonNodeArray.get(i).get(VALUE).textValue();
}
}
if (closeDateAsString == null || closeDateAsString.equals("")) {
return false;
}
closedDate = Utils.parseStringToCalendar(closeDateAsString, DHIS2_GMT_NEW_DATE_FORMAT).getTime();
if (closedDate == null) {
return false;
}
return closedDate.before(new Date());
}
use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class ServerAPIController method patchClosedDate.
/**
* Updates the orgUnit adding a closedDate
*/
static void patchClosedDate(String url, String orgUnitUID) throws ApiCallException {
// https://malariacare.psi.org/api/organisationUnits/u5jlxuod8xQ/closedDate
try {
String urlPathClosedDate = getPatchClosedDateUrl(url, orgUnitUID);
JSONObject data = prepareTodayDateValue();
Response response = ServerApiCallExecution.executeCall(data, urlPathClosedDate, "PATCH");
ServerApiUtils.checkResponse(response, null);
} catch (JSONException e) {
throw new ApiCallException(e);
}
}
use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class ServerAPIController method patchDescription.
static void patchDescription(OrganisationUnit organisationUnit) {
String url = ServerAPIController.getServerUrl();
try {
String urlPathClosedDescription = getPatchClosedDescriptionUrl(url, organisationUnit.getUid());
JSONObject data = parseOrganisationUnitDescriptionToJson(organisationUnit.getDescription());
Response response = ServerApiCallExecution.executeCall(data, urlPathClosedDescription, "PATCH");
ServerApiUtils.checkResponse(response, null);
} catch (Exception e) {
Log.e(TAG, String.format("patchDescriptionClosedDate(%s,%s): %s", url, organisationUnit.getUid(), e.getMessage()));
}
}
Aggregations