Search in sources :

Example 1 with Rating

use of com.willshex.blogwt.shared.api.datatype.Rating in project blogwt by billy1380.

the class RatingService method addRating.

@Override
public Rating addRating(Rating rating) {
    if (rating.created == null) {
        rating.created = new Date();
    }
    if (rating.by != null) {
        rating.byKey = Key.create(rating.by);
    }
    Key<Rating> key = provide().save().entity(rating).now();
    rating.id = keyToId(key);
    return rating;
}
Also used : Rating(com.willshex.blogwt.shared.api.datatype.Rating) Date(java.util.Date)

Example 2 with Rating

use of com.willshex.blogwt.shared.api.datatype.Rating in project blogwt by billy1380.

the class GetRatingsResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("ratings")) {
        JsonElement jsonRatings = jsonObject.get("ratings");
        if (jsonRatings != null) {
            ratings = new ArrayList<Rating>();
            Rating item = null;
            for (int i = 0; i < jsonRatings.getAsJsonArray().size(); i++) {
                if (jsonRatings.getAsJsonArray().get(i) != null) {
                    (item = new Rating()).fromJson(jsonRatings.getAsJsonArray().get(i).getAsJsonObject());
                    ratings.add(item);
                }
            }
        }
    }
    if (jsonObject.has("pager")) {
        JsonElement jsonPager = jsonObject.get("pager");
        if (jsonPager != null) {
            pager = new Pager();
            pager.fromJson(jsonPager.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Rating(com.willshex.blogwt.shared.api.datatype.Rating) Pager(com.willshex.blogwt.shared.api.Pager)

Example 3 with Rating

use of com.willshex.blogwt.shared.api.datatype.Rating in project blogwt by billy1380.

the class SubmitRatingResponse method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("rating")) {
        JsonElement jsonRating = jsonObject.get("rating");
        if (jsonRating != null) {
            rating = new Rating();
            rating.fromJson(jsonRating.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Rating(com.willshex.blogwt.shared.api.datatype.Rating)

Example 4 with Rating

use of com.willshex.blogwt.shared.api.datatype.Rating in project blogwt by billy1380.

the class RatingValidator method lookup.

public static Rating lookup(Rating rating, String name) throws InputValidationException {
    if (rating == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false;
    if (rating.id != null) {
        isIdLookup = true;
    }
    if (!isIdLookup)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Rating lookupRating = null;
    if (isIdLookup) {
        lookupRating = RatingServiceProvider.provide().getRating(rating.id);
    }
    if (lookupRating == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupRating;
}
Also used : Rating(com.willshex.blogwt.shared.api.datatype.Rating) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 5 with Rating

use of com.willshex.blogwt.shared.api.datatype.Rating in project blogwt by billy1380.

the class SubmitRatingRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("rating")) {
        JsonElement jsonRating = jsonObject.get("rating");
        if (jsonRating != null) {
            rating = new Rating();
            rating.fromJson(jsonRating.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Rating(com.willshex.blogwt.shared.api.datatype.Rating)

Aggregations

Rating (com.willshex.blogwt.shared.api.datatype.Rating)5 JsonElement (com.google.gson.JsonElement)3 Pager (com.willshex.blogwt.shared.api.Pager)1 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)1 Date (java.util.Date)1