Search in sources :

Example 1 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class DeviceListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    List<Device> devices = deviceDao.readAll(contributor.getLocale());
    model.addAttribute("devices", devices);
    return "analytics/device/list";
}
Also used : Device(ai.elimu.model.Device) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Device

use of ai.elimu.model.Device 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 3 with Device

use of ai.elimu.model.Device 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 4 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class NumberLearningEventDaoTest method testReadAllByDevice.

@Test
public void testReadAllByDevice() {
    Device device = new Device();
    device.setDeviceId("576de45ad9e0b07cf66");
    deviceDao.create(device);
    List<NumberLearningEvent> numberLearningEvents = numberLearningEventDao.readAll(device);
    assertThat(numberLearningEvents.size(), is(0));
    Number number = new Number();
    number.setValue(1);
    numberDao.create(number);
    NumberLearningEvent numberLearningEvent = new NumberLearningEvent();
    numberLearningEvent.setDevice(device);
    numberLearningEvent.setNumber(number);
    numberLearningEventDao.create(numberLearningEvent);
    numberLearningEvents = numberLearningEventDao.readAll(device);
    assertThat(numberLearningEvents.size(), is(1));
    assertThat(numberLearningEvents.get(0).getNumber().getValue(), is(1));
}
Also used : Number(ai.elimu.model.content.Number) Device(ai.elimu.model.Device) NumberLearningEvent(ai.elimu.model.analytics.NumberLearningEvent) Test(org.junit.Test)

Example 5 with Device

use of ai.elimu.model.Device in project webapp by elimu-ai.

the class StudentDaoTest method testStoreStudentWithTWoDevices.

@Test
public void testStoreStudentWithTWoDevices() {
    Set<Device> devices = new HashSet<>();
    Device device1 = new Device();
    device1.setDeviceId("2223947bec18b7ad");
    deviceDao.create(device1);
    devices.add(device1);
    Device device2 = new Device();
    device2.setDeviceId("679b35bb2322c6e4");
    deviceDao.create(device2);
    devices.add(device2);
    Student student = new Student();
    student.setUniqueId("2223947bec18b7ad_1");
    student.setDevices(devices);
    studentDao.create(student);
    Student studentStoredInDatabase = studentDao.read("2223947bec18b7ad_1");
    assertThat(studentStoredInDatabase.getDevices().size(), is(2));
}
Also used : Device(ai.elimu.model.Device) Student(ai.elimu.model.Student) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Device (ai.elimu.model.Device)12 Test (org.junit.Test)7 ApplicationOpenedEvent (ai.elimu.model.analytics.ApplicationOpenedEvent)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 HashSet (java.util.HashSet)3 JSONObject (org.json.JSONObject)3 Student (ai.elimu.model.Student)2 DeviceGson (ai.elimu.model.gson.DeviceGson)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 Calendar (java.util.Calendar)2 Contributor (ai.elimu.model.Contributor)1 LetterLearningEvent (ai.elimu.model.analytics.LetterLearningEvent)1 NumberLearningEvent (ai.elimu.model.analytics.NumberLearningEvent)1 Letter (ai.elimu.model.content.Letter)1 Number (ai.elimu.model.content.Number)1 Locale (ai.elimu.model.enums.Locale)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1