use of ai.elimu.model.analytics.ApplicationOpenedEvent in project webapp by elimu-ai.
the class ApplicationOpenedEventListController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
// To ease development/testing, auto-generate events
if (EnvironmentContextLoaderListener.env != Environment.PROD) {
generateEvents(contributor.getLocale());
}
List<ApplicationOpenedEvent> applicationOpenedEvents = applicationOpenedEventDao.readAll(contributor.getLocale());
model.addAttribute("applicationOpenedEvents", applicationOpenedEvents);
return "analytics/application-opened-event/list";
}
use of ai.elimu.model.analytics.ApplicationOpenedEvent 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.analytics.ApplicationOpenedEvent 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.analytics.ApplicationOpenedEvent 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.analytics.ApplicationOpenedEvent in project webapp by elimu-ai.
the class ApplicationOpenedEventDaoTest method testReadAllByLocale.
@Test
public void testReadAllByLocale() {
Locale locale = Locale.values()[(int) (Math.random() * Locale.values().length)];
logger.info("locale: " + locale);
List<ApplicationOpenedEvent> applicationOpenedEvents = applicationOpenedEventDao.readAll(locale);
assertThat(applicationOpenedEvents.size(), is(0));
Device device = new Device();
device.setLocale(locale);
deviceDao.create(device);
ApplicationOpenedEvent applicationOpenedEvent1 = new ApplicationOpenedEvent();
applicationOpenedEvent1.setDevice(device);
applicationOpenedEventDao.create(applicationOpenedEvent1);
ApplicationOpenedEvent applicationOpenedEvent2 = new ApplicationOpenedEvent();
applicationOpenedEvent2.setDevice(device);
applicationOpenedEventDao.create(applicationOpenedEvent2);
applicationOpenedEvents = applicationOpenedEventDao.readAll(locale);
assertThat(applicationOpenedEvents.size(), is(2));
}
Aggregations