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;
}
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();
}
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();
}
}
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;
}
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);
}
Aggregations