Search in sources :

Example 1 with UshahidiException

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;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Example 2 with UshahidiException

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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) ReportCategory(com.ushahidi.android.app.entities.ReportCategory) JsonSyntaxException(com.google.gson.JsonSyntaxException) Incidents(com.ushahidi.java.sdk.api.Incidents) UshahidiException(com.ushahidi.java.sdk.UshahidiException) ReportEntity(com.ushahidi.android.app.entities.ReportEntity)

Example 3 with UshahidiException

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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) Category(com.ushahidi.java.sdk.api.Category) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 4 with UshahidiException

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();
    }
}
Also used : UshahidiHttpClient(com.ushahidi.java.sdk.net.UshahidiHttpClient) JsonSyntaxException(com.google.gson.JsonSyntaxException) UshahidiApiVersion(com.ushahidi.android.app.json.UshahidiApiVersion) UshahidiException(com.ushahidi.java.sdk.UshahidiException)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)4 UshahidiException (com.ushahidi.java.sdk.UshahidiException)4 Util (com.ushahidi.android.app.util.Util)2 Category (com.ushahidi.java.sdk.api.Category)2 CategoryEntity (com.ushahidi.android.app.entities.CategoryEntity)1 CommentEntity (com.ushahidi.android.app.entities.CommentEntity)1 ReportCategory (com.ushahidi.android.app.entities.ReportCategory)1 ReportEntity (com.ushahidi.android.app.entities.ReportEntity)1 UshahidiApiVersion (com.ushahidi.android.app.json.UshahidiApiVersion)1 Incidents (com.ushahidi.java.sdk.api.Incidents)1 UshahidiHttpClient (com.ushahidi.java.sdk.net.UshahidiHttpClient)1