Search in sources :

Example 1 with ImageGson

use of ai.elimu.model.gson.content.multimedia.ImageGson in project webapp by elimu-ai.

the class JavaToGsonConverter method getImageGson.

public static ImageGson getImageGson(Image image) {
    if (image == null) {
        return null;
    } else {
        ImageGson imageGson = new ImageGson();
        imageGson.setId(image.getId());
        imageGson.setLocale(image.getLocale());
        imageGson.setTimeLastUpdate(image.getTimeLastUpdate());
        imageGson.setRevisionNumber(image.getRevisionNumber());
        imageGson.setContentStatus(image.getContentStatus());
        imageGson.setDownloadUrl("/image/" + image.getId() + "." + image.getImageFormat().toString().toLowerCase());
        imageGson.setDownloadSize(image.getBytes().length / 1024);
        imageGson.setContentType(image.getContentType());
        imageGson.setLiteracySkills(image.getLiteracySkills());
        imageGson.setNumeracySkills(image.getNumeracySkills());
        List<LetterGson> letters = new ArrayList<>();
        for (Letter letter : image.getLetters()) {
            LetterGson letterGson = getLetterGson(letter);
            letters.add(letterGson);
        }
        imageGson.setLetters(letters);
        List<NumberGson> numbers = new ArrayList<>();
        for (Number number : image.getNumbers()) {
            NumberGson numberGson = getNumberGson(number);
            numbers.add(numberGson);
        }
        imageGson.setNumbers(numbers);
        List<WordGson> words = new ArrayList<>();
        for (Word word : image.getWords()) {
            WordGson wordGson = getWordGson(word);
            words.add(wordGson);
        }
        imageGson.setWords(words);
        imageGson.setTitle(image.getTitle());
        imageGson.setImageFormat(image.getImageFormat());
        imageGson.setDominantColor(image.getDominantColor());
        return imageGson;
    }
}
Also used : Letter(ai.elimu.model.content.Letter) WordGson(ai.elimu.model.gson.content.WordGson) ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) ArrayList(java.util.ArrayList) LetterGson(ai.elimu.model.gson.content.LetterGson) NumberGson(ai.elimu.model.gson.content.NumberGson)

Example 2 with ImageGson

use of ai.elimu.model.gson.content.multimedia.ImageGson in project webapp by elimu-ai.

the class ImageRestController method list.

@RequestMapping("/list")
public String list(HttpServletRequest request, @RequestParam String deviceId, // TODO: checksum,
@RequestParam Locale locale) {
    logger.info("list");
    logger.info("request.getQueryString(): " + request.getQueryString());
    JSONArray jsonArray = new JSONArray();
    for (Image image : imageDao.readAllOrdered(locale)) {
        ImageGson imageGson = JavaToGsonConverter.getImageGson(image);
        String json = new Gson().toJson(imageGson);
        jsonArray.put(new JSONObject(json));
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("result", "success");
    jsonObject.put("images", jsonArray);
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ImageGson(ai.elimu.model.gson.content.multimedia.ImageGson) Gson(com.google.gson.Gson) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImageGson (ai.elimu.model.gson.content.multimedia.ImageGson)2 Letter (ai.elimu.model.content.Letter)1 Number (ai.elimu.model.content.Number)1 Word (ai.elimu.model.content.Word)1 Image (ai.elimu.model.content.multimedia.Image)1 LetterGson (ai.elimu.model.gson.content.LetterGson)1 NumberGson (ai.elimu.model.gson.content.NumberGson)1 WordGson (ai.elimu.model.gson.content.WordGson)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1