use of ai.elimu.model.Device in project webapp by elimu-ai.
the class ApplicationOpenedEventDaoTest method testReadAllByDevice.
@Test
public void testReadAllByDevice() {
Device device = new Device();
device.setDeviceId("bcaef51200ac6d92bdd81");
deviceDao.create(device);
List<ApplicationOpenedEvent> applicationOpenedEvents = applicationOpenedEventDao.readAll(device);
assertThat(applicationOpenedEvents.size(), is(0));
ApplicationOpenedEvent applicationOpenedEvent1 = new ApplicationOpenedEvent();
applicationOpenedEvent1.setDevice(device);
applicationOpenedEventDao.create(applicationOpenedEvent1);
ApplicationOpenedEvent applicationOpenedEvent2 = new ApplicationOpenedEvent();
applicationOpenedEventDao.create(applicationOpenedEvent2);
applicationOpenedEvents = applicationOpenedEventDao.readAll(device);
assertThat(applicationOpenedEvents.size(), is(1));
}
use of ai.elimu.model.Device in project webapp by elimu-ai.
the class DeviceDaoTest method testStoreNearbyDevices.
@Test
public void testStoreNearbyDevices() {
Device device = new Device();
device.setDeviceId("aaabbbccc111222333");
deviceDao.create(device);
assertThat(device.getDevicesNearby().size(), is(0));
Set<Device> nearbyDevices = new HashSet<>();
Device nearbyDevice1 = new Device();
nearbyDevice1.setDeviceId("dddeeefff444555666");
deviceDao.create(nearbyDevice1);
nearbyDevices.add(nearbyDevice1);
Device nearbyDevice2 = new Device();
nearbyDevice2.setDeviceId("ggghhhiii777888999");
deviceDao.create(nearbyDevice2);
nearbyDevices.add(nearbyDevice2);
device.setDevicesNearby(nearbyDevices);
deviceDao.update(device);
assertThat(device.getDevicesNearby().size(), is(2));
}
use of ai.elimu.model.Device in project webapp by elimu-ai.
the class ApplicationOpenedEventListController method generateEvents.
private List<ApplicationOpenedEvent> generateEvents(Locale locale) {
logger.info("generateEvents");
List<ApplicationOpenedEvent> applicationOpenedEvents = new ArrayList<>();
String[] eventFiles = new String[] { "application_opened_events_2017-05-25.log", "application_opened_events_2017-05-27.log", "application_opened_events_2017-05-28.log", "application_opened_events_2017-05-29.log", "application_opened_events_2017-05-30.log", "application_opened_events_2017-06-02.log", "application_opened_events_2017-06-03.log", "application_opened_events_2017-06-04.log", "application_opened_events_2017-06-05.log", "application_opened_events_2017-06-06.log", "application_opened_events_2017-06-07.log", "application_opened_events_2017-06-08.log", "application_opened_events_2017-06-09.log" };
for (String eventFile : eventFiles) {
logger.info("eventFile: " + eventFile);
URL url = getClass().getResource(eventFile);
try {
Reader reader = new FileReader(url.getFile());
List<String> lines = IOUtils.readLines(reader);
logger.info("lines.size(): " + lines.size());
reader.close();
for (String eventLine : lines) {
logger.info("eventLine: " + eventLine);
// Expected format: id:163|deviceId:2312aff4939750ea|time:1496843219926|packageName:ai.elimu.nyaqd|studentId:2312aff4939750ea_4
String deviceId = EventLineHelper.getDeviceId(eventLine);
Device device = deviceDao.read(deviceId);
logger.info("device: " + device);
if (device == null) {
device = new Device();
device.setDeviceId(deviceId);
device.setDeviceManufacturer("asdf");
device.setDeviceModel("asdf");
device.setDeviceSerial("asdf");
device.setRemoteAddress("0.0.0.0");
device.setOsVersion(23);
device.setLocale(locale);
deviceDao.create(device);
}
Calendar timeOfEvent = EventLineHelper.getTime(eventLine);
String packageName = EventLineHelper.getPackageName(eventLine);
ApplicationOpenedEvent existingApplicationOpenedEvent = applicationOpenedEventDao.read(device, timeOfEvent, packageName);
logger.info("existingApplicationOpenedEvent: " + existingApplicationOpenedEvent);
if (existingApplicationOpenedEvent == null) {
ApplicationOpenedEvent applicationOpenedEvent = new ApplicationOpenedEvent();
applicationOpenedEvent.setDevice(device);
applicationOpenedEvent.setCalendar(timeOfEvent);
applicationOpenedEvent.setPackageName(packageName);
applicationOpenedEventDao.create(applicationOpenedEvent);
applicationOpenedEvents.add(applicationOpenedEvent);
}
}
} catch (FileNotFoundException ex) {
logger.error(null, ex);
} catch (IOException ex) {
logger.error(null, ex);
}
}
return applicationOpenedEvents;
}
use of ai.elimu.model.Device in project webapp by elimu-ai.
the class ApplicationOpenedEventRestController method create.
@RequestMapping("/create")
public String create(HttpServletRequest request, // TODO: checksum,
@RequestParam MultipartFile multipartFile) {
logger.info("create");
logger.info("request.getQueryString(): " + request.getQueryString());
if (!multipartFile.isEmpty()) {
try {
byte[] bytes = multipartFile.getBytes();
Reader reader = new CharSequenceReader((new String(bytes)));
List<String> lines = IOUtils.readLines(reader);
logger.info("lines.size(): " + lines.size());
reader.close();
for (String eventLine : lines) {
logger.info("eventLine: " + eventLine);
// Expected format: id:163|deviceId:2312aff4939750ea|time:1496843219926|packageName:ai.elimu.nyaqd|studentId:2312aff4939750ea_4
String deviceId = EventLineHelper.getDeviceId(eventLine);
Device device = deviceDao.read(deviceId);
logger.info("device: " + device);
Calendar timeOfEvent = EventLineHelper.getTime(eventLine);
String packageName = EventLineHelper.getPackageName(eventLine);
ApplicationOpenedEvent existingApplicationOpenedEvent = applicationOpenedEventDao.read(device, timeOfEvent, packageName);
logger.info("existingApplicationOpenedEvent: " + existingApplicationOpenedEvent);
if (existingApplicationOpenedEvent == null) {
ApplicationOpenedEvent applicationOpenedEvent = new ApplicationOpenedEvent();
applicationOpenedEvent.setDevice(device);
applicationOpenedEvent.setCalendar(timeOfEvent);
applicationOpenedEvent.setPackageName(packageName);
applicationOpenedEventDao.create(applicationOpenedEvent);
}
}
} catch (IOException ex) {
logger.error(null, ex);
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("result", "success");
// TODO: handle error
logger.info("jsonObject: " + jsonObject);
return jsonObject.toString();
}
use of ai.elimu.model.Device in project webapp by elimu-ai.
the class LetterLearningEventDaoTest method testReadAllByDevice.
@Test
public void testReadAllByDevice() {
Device device = new Device();
device.setDeviceId("ddhe72a08347cd29bd3f43d");
deviceDao.create(device);
List<LetterLearningEvent> letterLearningEvents = letterLearningEventDao.readAll(device);
assertThat(letterLearningEvents.size(), is(0));
Letter letter = new Letter();
letter.setText("a");
letterDao.create(letter);
LetterLearningEvent letterLearningEvent = new LetterLearningEvent();
letterLearningEvent.setDevice(device);
letterLearningEvent.setLetter(letter);
letterLearningEventDao.create(letterLearningEvent);
letterLearningEvents = letterLearningEventDao.readAll(device);
assertThat(letterLearningEvents.size(), is(1));
assertThat(letterLearningEvents.get(0).getLetter().getText(), is("a"));
}
Aggregations