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