use of com.ushahidi.java.sdk.UshahidiException in project Ushahidi_Android by ushahidi.
the class CommentsApi method getCommentsList.
/**
* Fetch report's comments using the Ushahidi API
*
* @param reportId
* The report ID
* @return
*/
public List<CommentEntity> getCommentsList(int reportId) {
new Util().log("Save comments");
if (processingResult) {
try {
for (com.ushahidi.java.sdk.api.Comment c : task.reportId(reportId)) {
CommentEntity comment = new CommentEntity();
comment.addComment(c);
comments.add(comment);
}
} catch (UshahidiException e) {
processingResult = false;
log("CommentsApi getCommentsList", e);
} catch (JsonSyntaxException e) {
processingResult = false;
log("CommentsApi getCommentsList", e);
}
}
return comments;
}
use of com.ushahidi.java.sdk.UshahidiException in project Ushahidi_Android by ushahidi.
the class ReportsApi method getReportList.
/**
* Fetch reports via the Ushahidi API
*
* @param context The calling activity
* @return The list of reports
*/
private List<ReportEntity> getReportList(Context context) {
log("Save report");
if (processingResult) {
try {
List<Incidents> incidents = task.all();
if (incidents != null && incidents.size() > 0) {
for (Incidents i : incidents) {
ReportEntity report = new ReportEntity();
report.setIncident(i.incident);
reports.add(report);
// save categories
if ((i.getCategories() != null) && (i.getCategories().size() > 0)) {
for (Category c : i.getCategories()) {
saveCategories(c.getId(), i.incident.getId());
}
}
// save media
if ((i.getMedia() != null) && (!i.getMedia().isEmpty())) {
for (com.ushahidi.java.sdk.api.Media m : i.getMedia()) {
// find photos, it's type is 1
if (m != null) {
if (m.getType() == 1) {
if (m.getLinkUrl() != null) {
//This will capture entire picture descriptor to prevent duplicates
final String fileName = m.getLinkUrl().substring(m.getLinkUrl().lastIndexOf('/') + 1, m.getLinkUrl().length());
// save details of photo to database
saveMedia(m.getId(), i.incident.getId(), m.getType(), fileName);
saveImages(m.getLinkUrl(), fileName, context);
}
} else {
// other media type to database
if (m.getLink() != null)
saveMedia(m.getId(), (int) i.incident.getId(), m.getType(), m.getLink());
}
}
}
}
}
}
} catch (UshahidiException e) {
log("UshahidiException", e);
processingResult = false;
} catch (JsonSyntaxException e) {
log("JSONSyntaxException", e);
processingResult = false;
}
}
return reports;
}
use of com.ushahidi.java.sdk.UshahidiException in project Ushahidi_Android by ushahidi.
the class CategoriesApi method getCategoriesList.
/**
* Fetch categories using the Ushahidi API
*
* @return boolean Successful return true otherwise return false
*/
public boolean getCategoriesList() {
new Util().log("Save categories list");
if (processingResult) {
try {
List<Category> cats = task.all();
if (cats != null) {
for (com.ushahidi.java.sdk.api.Category cat : cats) {
CategoryEntity category = new CategoryEntity();
category.addCategory(cat);
categories.add(category);
}
return saveCategories(categories);
}
} catch (UshahidiException e) {
log("UshahidiException", e);
processingResult = false;
} catch (JsonSyntaxException e) {
log("JSONSyntaxException", e);
}
}
return false;
}
use of com.ushahidi.java.sdk.UshahidiException in project Ushahidi_Android by ushahidi.
the class ApiUtils method updateDomain.
/**
* Check if an ushahidi deployment has changed it's HTTP protocol to HTTPS
* or not. Then update if it has.
*
* @param context
* - the calling activity.
*/
public static void updateDomain(Context context) {
UshahidiHttpClient client = new UshahidiHttpClient();
Preferences.loadSettings(context);
StringBuilder uriBuilder = new StringBuilder(Preferences.domain);
uriBuilder.append("/api?task=version");
uriBuilder.append("&resp=json");
try {
if (client != null) {
String jsonString = client.sendGetRequest(uriBuilder.toString());
UshahidiApiVersion ver = BaseTask.fromString(jsonString, UshahidiApiVersion.class);
String domain = ver.getDomain();
new Util().log(String.format("%s %s ", "Update domain", domain));
Preferences.domain = domain;
String ogsVer = client.sendGetRequest(Preferences.domain + "/opengeosms/version");
Preferences.ogsPluginVersion = ogsVer == null ? "" : trimVersion(ogsVer);
String sms = ver.getSms();
Preferences.phonenumber = sms != null ? sms : "";
// save changes
Preferences.saveSettings(context);
}
} catch (UshahidiException e) {
new Util().log(CLASS_TAG, e);
} catch (JsonSyntaxException e) {
e.getMessage();
}
}
Aggregations