Skip to content

Commit dc4efd6

Browse files
committed
feat: add student entity
#2103
1 parent b7a34ba commit dc4efd6

File tree

15 files changed

+172
-104
lines changed

15 files changed

+172
-104
lines changed

pom-dependency-tree.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ai.elimu:webapp:war:2.6.10-SNAPSHOT
1+
ai.elimu:webapp:war:2.6.11-SNAPSHOT
22
+- ai.elimu:model:jar:model-2.0.97:compile
33
| \- com.google.code.gson:gson:jar:2.13.0:compile
44
| \- com.google.errorprone:error_prone_annotations:jar:2.37.0:compile

src/main/java/ai/elimu/dao/DeviceDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import ai.elimu.entity.Device;
66

7+
@Deprecated
78
public interface DeviceDao extends GenericDao<Device> {
89

910
Device read(String androidId) throws DataAccessException;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ai.elimu.dao;
2+
3+
import org.springframework.dao.DataAccessException;
4+
import ai.elimu.entity.analytics.students.Student;
5+
6+
public interface StudentDao extends GenericDao<Student> {
7+
8+
Student read(String androidId) throws DataAccessException;
9+
}

src/main/java/ai/elimu/dao/jpa/DeviceDaoJpa.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.springframework.dao.DataAccessException;
88

9+
@Deprecated
910
public class DeviceDaoJpa extends GenericDaoJpa<Device> implements DeviceDao {
1011

1112
@Override
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ai.elimu.dao.jpa;
2+
3+
import jakarta.persistence.NoResultException;
4+
import ai.elimu.dao.StudentDao;
5+
import ai.elimu.entity.analytics.students.Student;
6+
import org.springframework.dao.DataAccessException;
7+
8+
public class StudentDaoJpa extends GenericDaoJpa<Student> implements StudentDao {
9+
10+
@Override
11+
public Student read(String androidId) throws DataAccessException {
12+
try {
13+
return (Student) em.createQuery(
14+
"SELECT s " +
15+
"FROM Student s " +
16+
"WHERE s.androidId = :androidId")
17+
.setParameter("androidId", androidId)
18+
.getSingleResult();
19+
} catch (NoResultException e) {
20+
return null;
21+
}
22+
}
23+
}

src/main/java/ai/elimu/entity/Device.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@Entity
1313
@Getter
1414
@Setter
15+
@Deprecated
1516
public class Device extends BaseEntity {
1617

1718
@NotNull
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ai.elimu.entity.analytics.students;
2+
3+
import ai.elimu.entity.BaseEntity;
4+
import jakarta.persistence.Column;
5+
import jakarta.persistence.Entity;
6+
import jakarta.validation.constraints.NotNull;
7+
import lombok.Getter;
8+
import lombok.Setter;
9+
10+
@Entity
11+
@Getter
12+
@Setter
13+
public class Student extends BaseEntity {
14+
15+
/**
16+
* A 64-bit number (expressed as a hexadecimal string), unique to each combination of
17+
* app-signing key, user, and device.
18+
*
19+
* See https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID
20+
*/
21+
@NotNull
22+
@Column(unique = true)
23+
private String androidId;
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ai.elimu.web.analytics.students;
2+
3+
import ai.elimu.dao.StudentDao;
4+
import ai.elimu.entity.analytics.students.Student;
5+
import ai.elimu.util.AnalyticsHelper;
6+
import lombok.RequiredArgsConstructor;
7+
import lombok.extern.slf4j.Slf4j;
8+
9+
import java.util.List;
10+
11+
import org.springframework.stereotype.Controller;
12+
import org.springframework.ui.Model;
13+
import org.springframework.web.bind.annotation.GetMapping;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
16+
@Controller
17+
@RequestMapping("/analytics/students")
18+
@RequiredArgsConstructor
19+
@Slf4j
20+
public class StudentsListController {
21+
22+
private final StudentDao studentDao;
23+
24+
@GetMapping
25+
public String handleRequest(Model model) {
26+
log.info("handleRequest");
27+
28+
List<Student> students = studentDao.readAll();
29+
for (Student student : students) {
30+
student.setAndroidId(AnalyticsHelper.redactAndroidId(student.getAndroidId()));
31+
}
32+
model.addAttribute("students", students);
33+
34+
return "analytics/students/list";
35+
}
36+
}

src/main/java/ai/elimu/web/servlet/CustomDispatcherServlet.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import ai.elimu.dao.SoundDao;
1111
import ai.elimu.dao.StoryBookChapterDao;
1212
import ai.elimu.dao.StoryBookDao;
13+
import ai.elimu.dao.StudentDao;
1314
import ai.elimu.dao.VideoDao;
1415
import ai.elimu.dao.WordDao;
16+
import ai.elimu.entity.analytics.students.Student;
1517
import ai.elimu.entity.application.Application;
1618
import ai.elimu.entity.content.Emoji;
1719
import ai.elimu.entity.content.Letter;
@@ -294,5 +296,20 @@ private void populateDatabase(WebApplicationContext webApplicationContext) {
294296
application.setApplicationStatus(ApplicationStatus.MISSING_APK);
295297
application.setContributor(contributor);
296298
applicationDao.create(application);
299+
300+
301+
StudentDao studentDao = (StudentDao) webApplicationContext.getBean("studentDao");
302+
303+
Student student1 = new Student();
304+
student1.setAndroidId("e387e38700000001");
305+
studentDao.create(student1);
306+
307+
Student student2 = new Student();
308+
student2.setAndroidId("e387e38700000002");
309+
studentDao.create(student2);
310+
311+
Student student3 = new Student();
312+
student3.setAndroidId("e387e38700000003");
313+
studentDao.create(student3);
297314
}
298315
}

src/main/resources/META-INF/jpa-schema-export.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575

7676
drop table if exists StoryBookPeerReviewEvent;
7777

78+
drop table if exists Student;
79+
7880
drop table if exists Syllable;
7981

8082
drop table if exists Syllable_Sound;
@@ -479,6 +481,12 @@
479481
primary key (id)
480482
) type=MyISAM;
481483

484+
create table Student (
485+
id bigint not null auto_increment,
486+
androidId varchar(255),
487+
primary key (id)
488+
) type=MyISAM;
489+
482490
create table Syllable (
483491
id bigint not null auto_increment,
484492
contentStatus varchar(255),
@@ -624,6 +632,9 @@
624632
alter table Device
625633
add constraint UK_c2646199whiqrkjbht7hwyr3v unique (androidId);
626634

635+
alter table Student
636+
add constraint UK_ac9n51iqy52mto0jrnkqlk3ld unique (androidId);
637+
627638
alter table Application
628639
add constraint FKn1pft600om9qs7dn754chjk67
629640
foreign key (contributor_id)

0 commit comments

Comments
 (0)