Search in sources :

Example 1 with DeviceGson

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

the class DeviceRestController method create.

@RequestMapping("/create")
public String create(HttpServletRequest request, @RequestParam String deviceId, // TODO: checksum
@RequestParam String deviceManufacturer, @RequestParam String deviceModel, @RequestParam String deviceSerial, @RequestParam Integer osVersion, @RequestParam String applicationId, @RequestParam Integer appVersionCode, @RequestParam Locale locale) {
    logger.info("create");
    logger.info("request.getQueryString(): " + request.getQueryString());
    logger.info("request.getRemoteAddr(): " + request.getRemoteAddr());
    JSONObject jSONObject = new JSONObject();
    Device device = deviceDao.read(deviceId);
    if (device != null) {
        jSONObject.put("result", "error");
        jSONObject.put("description", "Device already exists");
    } else {
        device = new Device();
        device.setDeviceId(deviceId);
        device.setDeviceManufacturer(deviceManufacturer);
        device.setDeviceModel(deviceModel);
        device.setDeviceSerial(deviceSerial);
        device.setTimeRegistered(Calendar.getInstance());
        device.setRemoteAddress(request.getRemoteAddr());
        device.setOsVersion(osVersion);
        device.setLocale(locale);
        deviceDao.create(device);
        DeviceGson deviceGson = JavaToGsonConverter.getDeviceGson(device);
        jSONObject.put("result", "success");
        jSONObject.put("device", new Gson().toJson(deviceGson));
    }
    logger.info("jSONObject: " + jSONObject);
    return jSONObject.toString();
}
Also used : JSONObject(org.json.JSONObject) Device(ai.elimu.model.Device) Gson(com.google.gson.Gson) DeviceGson(ai.elimu.model.gson.DeviceGson) DeviceGson(ai.elimu.model.gson.DeviceGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DeviceGson

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

the class DeviceRestController method read.

@RequestMapping("/read/{deviceId}")
public String read(@PathVariable String deviceId) {
    logger.info("read");
    logger.info("deviceId: " + deviceId);
    JSONObject jSONObject = new JSONObject();
    Device device = deviceDao.read(deviceId);
    if (device == null) {
        jSONObject.put("result", "error");
        jSONObject.put("description", "Device not found");
    } else {
        DeviceGson deviceGson = JavaToGsonConverter.getDeviceGson(device);
        jSONObject.put("result", "success");
        jSONObject.put("device", new Gson().toJson(deviceGson));
    }
    logger.info("jSONObject: " + jSONObject);
    return jSONObject.toString();
}
Also used : JSONObject(org.json.JSONObject) Device(ai.elimu.model.Device) Gson(com.google.gson.Gson) DeviceGson(ai.elimu.model.gson.DeviceGson) DeviceGson(ai.elimu.model.gson.DeviceGson) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DeviceGson

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

the class JavaToGsonConverter method getDeviceGson.

public static DeviceGson getDeviceGson(Device device) {
    if (device == null) {
        return null;
    } else {
        DeviceGson deviceGson = new DeviceGson();
        deviceGson.setId(device.getId());
        deviceGson.setDeviceId(device.getDeviceId());
        return deviceGson;
    }
}
Also used : DeviceGson(ai.elimu.model.gson.DeviceGson)

Aggregations

DeviceGson (ai.elimu.model.gson.DeviceGson)3 Device (ai.elimu.model.Device)2 Gson (com.google.gson.Gson)2 JSONObject (org.json.JSONObject)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2