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