Search in sources :

Example 1 with AppCollectionGson

use of ai.elimu.model.gson.project.AppCollectionGson in project webapp by elimu-ai.

the class JavaToGsonConverter method getAppCollectionGson.

public static AppCollectionGson getAppCollectionGson(AppCollection appCollection) {
    if (appCollection == null) {
        return null;
    } else {
        AppCollectionGson appCollectionGson = new AppCollectionGson();
        appCollectionGson.setId(appCollection.getId());
        List<AppCategoryGson> appCategories = new ArrayList<>();
        for (AppCategory appCategory : appCollection.getAppCategories()) {
            AppCategoryGson appCategoryGson = getAppCategoryGson(appCategory);
            appCategories.add(appCategoryGson);
        }
        appCollectionGson.setAppCategories(appCategories);
        return appCollectionGson;
    }
}
Also used : AppCollectionGson(ai.elimu.model.gson.project.AppCollectionGson) AppCategoryGson(ai.elimu.model.gson.project.AppCategoryGson) ArrayList(java.util.ArrayList) AppCategory(ai.elimu.model.project.AppCategory)

Example 2 with AppCollectionGson

use of ai.elimu.model.gson.project.AppCollectionGson in project webapp by elimu-ai.

the class AppCollectionRestController method get.

@RequestMapping(method = RequestMethod.GET)
public String get(HttpServletRequest request, @PathVariable Long appCollectionId, @RequestParam String licenseEmail, @RequestParam String licenseNumber) {
    logger.info("get");
    logger.info("request.getQueryString(): " + request.getQueryString());
    logger.info("request.getRemoteAddr(): " + request.getRemoteAddr());
    JSONObject jsonObject = new JSONObject();
    License license = licenseDao.read(licenseEmail, licenseNumber);
    if (license == null) {
        jsonObject.put("result", "error");
        jsonObject.put("description", "Invalid license");
    } else {
        AppCollection appCollection = appCollectionDao.read(appCollectionId);
        if (appCollection == null) {
            jsonObject.put("result", "error");
            jsonObject.put("description", "AppCollection not found");
        } else {
            // TODO: verify that the AppCollection matches the one associated with the provided License
            AppCollectionGson appCollectionGson = JavaToGsonConverter.getAppCollectionGson(appCollection);
            String appCollectionJson = new Gson().toJson(appCollectionGson);
            jsonObject.put("result", "success");
            jsonObject.put("appCollection", new JSONObject(appCollectionJson));
        }
    }
    logger.info("jsonObject: " + jsonObject);
    return jsonObject.toString();
}
Also used : AppCollectionGson(ai.elimu.model.gson.project.AppCollectionGson) JSONObject(org.json.JSONObject) License(ai.elimu.model.project.License) AppCollectionGson(ai.elimu.model.gson.project.AppCollectionGson) Gson(com.google.gson.Gson) AppCollection(ai.elimu.model.project.AppCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AppCollectionGson (ai.elimu.model.gson.project.AppCollectionGson)2 AppCategoryGson (ai.elimu.model.gson.project.AppCategoryGson)1 AppCategory (ai.elimu.model.project.AppCategory)1 AppCollection (ai.elimu.model.project.AppCollection)1 License (ai.elimu.model.project.License)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1