Search in sources :

Example 91 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project rhino by PLOS.

the class SyndicationView method serialize.

@Override
public JsonElement serialize(JsonSerializationContext context) {
    JsonObject serialized = new JsonObject();
    serialized.add("revision", context.serialize(ArticleRevisionView.getView(syndication.getArticleRevision())));
    serialized.addProperty("target", syndication.getTarget());
    serialized.addProperty("status", syndication.getStatus());
    serialized.addProperty("submissionCount", syndication.getSubmissionCount());
    serialized.add("lastSubmitTimestamp", context.serialize(syndication.getLastSubmitTimestamp()));
    return serialized;
}
Also used : JsonObject(com.google.gson.JsonObject)

Example 92 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.

the class UserEmailApi method post.

@Post
public GenericResponse post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    JsonObject errorMessages = new JsonObject();
    if ((request.sendWelcomeMail() || request.sendBirthdayMail()) && request.getUserId() == null)
        errorMessages.addProperty("userId", GenericRequest.ERR_USER_ID_REQUIRED);
    if (request.sendEmailVerificationMail() && request.getUserId() == null && (request.getEmail() == null || request.getEmail().trim().isEmpty()))
        errorMessages.addProperty("email", GenericRequest.ERR_EMAIL_REQUIRED);
    if (request.sendPasswordResetMail() && (request.getEmail() == null || request.getEmail().trim().isEmpty()))
        errorMessages.addProperty("email", GenericRequest.ERR_EMAIL_REQUIRED);
    if (errorMessages.entrySet().size() > 0)
        throw new InvalidArgumentException(errorMessages);
    Language language = request.getLanguage() == null ? // User facing requests
    UxModeFilter.getDisplayLanguage() : // Offline requests
    request.getLanguage();
    if (request.sendWelcomeMail())
        UserDataUtil.sendWelcomeMail(request.getUserId(), language);
    if (request.sendEmailVerificationMail()) {
        if (request.getUserId() != null)
            UserDataUtil.sendEmailVerificationMail(request.getUserId(), language);
        else
            UserDataUtil.sendEmailVerificationMail(request.getEmail(), language);
    }
    if (request.sendPasswordResetMail())
        UserDataUtil.sendPasswordResetMail(request.getEmail(), language);
    if (request.sendBirthdayMail())
        throw new InvalidArgumentException("Feature not yet supported !");
    return new GenericResponse();
}
Also used : InvalidArgumentException(com.pratilipi.common.exception.InvalidArgumentException) Language(com.pratilipi.common.type.Language) GenericResponse(com.pratilipi.api.shared.GenericResponse) JsonObject(com.google.gson.JsonObject) Post(com.pratilipi.api.annotation.Post)

Example 93 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.

the class FacebookApi method postScrapeRequest.

public static void postScrapeRequest(String url) throws UnexpectedServerException {
    Map<String, String> paramsMap = new HashMap<String, String>();
    paramsMap.put("id", url);
    paramsMap.put("scrape", "true");
    paramsMap.put("access_token", getAccessToken());
    String responsePayload = HttpUtil.doPost(GRAPH_API_2p4_URL, paramsMap);
    JsonObject responseJson = new Gson().fromJson(responsePayload, JsonObject.class);
    if (responseJson.get("error") != null) {
        logger.log(Level.SEVERE, "Facebook scrapping for url: " + url + " failed with error \"" + responseJson.get("error") + "\"");
        throw new UnexpectedServerException();
    }
}
Also used : UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 94 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.

the class FirebaseApi method sendCloudMessage.

@Deprecated
public static String sendCloudMessage(List<String> fcmTokenList, String message, String tag, String androidHandler, String sourceId, String sourceImageUrl, String displayImageUrl) throws UnexpectedServerException {
    Map<String, String> headersMap = new HashMap<>();
    headersMap.put("Authorization", "key=" + getFcmServerKey());
    JsonObject notificationJson = new JsonObject();
    notificationJson.addProperty("body", message);
    notificationJson.addProperty("tag", tag);
    notificationJson.addProperty("sound", "disabled");
    notificationJson.addProperty("icon", "ic_pratilipi_notification_icon");
    notificationJson.addProperty("click_action", androidHandler);
    JsonObject dataJson = new JsonObject();
    dataJson.addProperty("sourceId", sourceId);
    dataJson.addProperty("sourceImageUrl", sourceImageUrl);
    dataJson.addProperty("displayImageUrl", displayImageUrl);
    JsonObject bodyJson = new JsonObject();
    bodyJson.add("registration_ids", new Gson().toJsonTree(fcmTokenList));
    bodyJson.add("notification", notificationJson);
    bodyJson.add("data", dataJson);
    String responsePayload = HttpUtil.doPost(CLOUD_MESSAGING_API_URL, headersMap, bodyJson);
    // Firebase might return with one or more error responses.
    for (JsonElement resultJson : new Gson().fromJson(responsePayload, JsonElement.class).getAsJsonObject().get("results").getAsJsonArray()) if (resultJson.getAsJsonObject().get("error") != null)
        logger.log(Level.SEVERE, "Firebase responded with error: " + resultJson.getAsJsonObject().get("error").getAsString());
    return responsePayload;
}
Also used : HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 95 with JsonObject

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project pratilipi by Pratilipi.

the class RtdbAccessorFirebaseImpl method _getUserPreferenceRtdb.

private UserPreferenceRtdb _getUserPreferenceRtdb(JsonObject json) {
    if (json.has("emailFrequency")) {
        String emailFrequency = json.get("emailFrequency").getAsString();
        if (emailFrequency.equals("ONCE A DAY")) {
            json.remove("emailFrequency");
            json.addProperty("emailFrequency", EmailFrequency.DAILY.name());
        } else if (emailFrequency.equals("ONCE A WEEK")) {
            json.remove("emailFrequency");
            json.addProperty("emailFrequency", EmailFrequency.WEEKLY.name());
        }
    }
    if (json.has("notificationSubscriptions")) {
        JsonObject notifSubscriptionsJson = json.get("notificationSubscriptions").getAsJsonObject();
        List<String> invalidTypes = new ArrayList<>();
        for (Entry<String, JsonElement> entry : notifSubscriptionsJson.entrySet()) {
            try {
                NotificationType.valueOf(entry.getKey());
            } catch (IllegalArgumentException ex) {
                invalidTypes.add(entry.getKey());
            }
        }
        for (String invalidType : invalidTypes) notifSubscriptionsJson.remove(invalidType);
    }
    return new Gson().fromJson(json, UserPreferenceRtdbImpl.class);
}
Also used : JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Aggregations

JsonObject (com.google.gson.JsonObject)5111 JsonArray (com.google.gson.JsonArray)1162 JsonElement (com.google.gson.JsonElement)1084 JsonParser (com.google.gson.JsonParser)710 Test (org.junit.Test)491 IOException (java.io.IOException)471 JsonPrimitive (com.google.gson.JsonPrimitive)387 ArrayList (java.util.ArrayList)376 Gson (com.google.gson.Gson)369 HashMap (java.util.HashMap)324 Map (java.util.Map)269 Test (org.testng.annotations.Test)208 Test (org.junit.jupiter.api.Test)201 File (java.io.File)146 List (java.util.List)142 InputStreamReader (java.io.InputStreamReader)135 JsonParseException (com.google.gson.JsonParseException)121 GsonBuilder (com.google.gson.GsonBuilder)93 JsonSyntaxException (com.google.gson.JsonSyntaxException)88 Nonnull (javax.annotation.Nonnull)87