Skip to content

Commit

Permalink
VKT(Backend): Create new ExaminerExamEvent table for exams of good an…
Browse files Browse the repository at this point in the history
…d satisfactory level. Drop references to examiners from ExamEvent table.
  • Loading branch information
pkoivisto committed Nov 7, 2024
1 parent b885ce8 commit b022a70
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 58 deletions.
16 changes: 1 addition & 15 deletions backend/vkt/src/main/java/fi/oph/vkt/model/ExamEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,23 @@
@Setter
@Entity
@Table(name = "exam_event")
public class ExamEvent extends BaseEntity {
public class ExamEvent extends ExamEventCommon {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "exam_event_id", nullable = false)
private long id;

@Column(name = "language", nullable = false)
@Enumerated(value = EnumType.STRING)
private ExamLanguage language;

@Column(name = "level", nullable = false)
@Enumerated(value = EnumType.STRING)
private ExamLevel level;

@Column(name = "date", nullable = false)
private LocalDate date;

@Column(name = "registration_opens", nullable = false)
private LocalDateTime registrationOpens;

@Column(name = "registration_closes", nullable = false)
private LocalDateTime registrationCloses;

@Column(name = "is_hidden", nullable = false)
private boolean isHidden;

@Column(name = "max_participants", nullable = false)
private long maxParticipants;

Expand All @@ -49,8 +39,4 @@ public class ExamEvent extends BaseEntity {

@OneToMany(mappedBy = "examEvent")
private List<Reservation> reservations = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "examiner_id", referencedColumnName = "examiner_id")
private Examiner examiner;
}
27 changes: 27 additions & 0 deletions backend/vkt/src/main/java/fi/oph/vkt/model/ExamEventCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fi.oph.vkt.model;

import fi.oph.vkt.model.type.ExamLanguage;
import jakarta.persistence.Column;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@MappedSuperclass
public class ExamEventCommon extends BaseEntity {

// TODO Is it ok to assume ExaminerExamEvents also have exactly one language?
@Column(name = "language", nullable = false)
@Enumerated(value = EnumType.STRING)
private ExamLanguage language;

@Column(name = "date", nullable = false)
private LocalDate date;

@Column(name = "is_hidden", nullable = false)
private boolean isHidden;
}
2 changes: 1 addition & 1 deletion backend/vkt/src/main/java/fi/oph/vkt/model/Examiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Examiner extends BaseEntity {
private boolean examLanguageSwedish;

@OneToMany(mappedBy = "examiner")
private List<ExamEvent> examEvents = new ArrayList<>();
private List<ExaminerExamEvent> examEvents = new ArrayList<>();

@Column(name = "is_public", nullable = false)
private boolean isPublic;
Expand Down
40 changes: 40 additions & 0 deletions backend/vkt/src/main/java/fi/oph/vkt/model/ExaminerExamEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fi.oph.vkt.model;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "examiner_exam_event")
public class ExaminerExamEvent extends ExamEventCommon {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "examiner_exam_event_id", nullable = false)
private long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "examiner_id", referencedColumnName = "examiner_id")
private Examiner examiner;

@Column(name = "registration_closes")
private LocalDateTime registrationCloses;

@Column(name = "max_participants")
private Long maxParticipants;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "municipality_id", referencedColumnName = "municipality_id", nullable = false)
private Municipality municipality;

@Column(name = "location", nullable = false)
private String location;
//@OneToMany(mappedBy = "examinerExamEvent")
//private List<EnrollmentAppointment> enrollments = new ArrayList<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fi.oph.vkt.api.dto.PublicMunicipalityDTO;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.Examiner;
import fi.oph.vkt.model.ExaminerExamEvent;
import fi.oph.vkt.model.Municipality;
import fi.oph.vkt.model.type.ExamLanguage;
import fi.oph.vkt.repository.ExaminerRepository;
Expand All @@ -25,12 +26,10 @@ private static PublicMunicipalityDTO toPublicMunicipalityDTO(Municipality munici
return PublicMunicipalityDTO.builder().fi(municipality.getNameFI()).sv(municipality.getNameSV()).build();
}

private static PublicExaminerExamDateDTO toPublicExaminerExamDateDTO(ExamEvent examEvent) {
return PublicExaminerExamDateDTO
.builder()
.examDate(examEvent.getDate())
.isFull(examEvent.getMaxParticipants() <= examEvent.getEnrollments().size())
.build();
private static PublicExaminerExamDateDTO toPublicExaminerExamDateDTO(ExaminerExamEvent examEvent) {
// TODO If maxParticipants is set, compare it against number of EnrollmentAppointments linked to examEvent
final boolean isFull = examEvent.getMaxParticipants() != null;
return PublicExaminerExamDateDTO.builder().examDate(examEvent.getDate()).isFull(isFull).build();
}

private static PublicExaminerDTO toPublicExaminerDTO(Examiner examiner) {
Expand Down
87 changes: 51 additions & 36 deletions backend/vkt/src/main/resources/db/changelog/db.changelog-1.0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1020,47 +1020,11 @@
referencedTableName="municipality"
referencedColumnNames="municipality_id"/>
</changeSet>
<changeSet id="2024-10-15-exam_event-add-reference-to-examiner" author="pkoivisto">
<dropUniqueConstraint tableName="exam_event" constraintName="uk_exam_event_language_level_date"/>
<addColumn tableName="exam_event">
<column name="examiner_id" type="BIGINT"/>
</addColumn>
<addForeignKeyConstraint
baseTableName="exam_event"
baseColumnNames="examiner_id"
constraintName="fk_exam_event_examiner_id"
referencedTableName="examiner"
referencedColumnNames="examiner_id"/>
</changeSet>
<changeSet id="2024-10-15-exam_level-new-value" author="pkoivisto">
<insert tableName="exam_level">
<column name="name" value="GOOD_AND_SATISFACTORY"/>
</insert>
</changeSet>
<changeSet id="2024-10-15-unique-exam-event-language-level-date-examiner-on-psql" author="pkoivisto">
<preConditions onFail="CONTINUE">
<dbms type="postgresql"/>
</preConditions>
<sql>
<![CDATA[
ALTER TABLE exam_event
ADD CONSTRAINT uk_exam_event_language_level_date_examiner UNIQUE NULLS NOT DISTINCT (language, level, date, examiner_id)
]]>
</sql>
</changeSet>
<changeSet id="2024-10-15-unique-exam-event-language-level-date-examiner-on-hsqldb" author="pkoivisto">
<preConditions onFail="CONTINUE">
<dbms type="hsqldb"/>
</preConditions>
<sql>
<![CDATA[
SET
DATABASE SQL UNIQUE NULLS FALSE
]]>
</sql>
<addUniqueConstraint tableName="exam_event" columnNames="language, level, date, examiner_id"
constraintName="uk_exam_event_language_level_date_examiner"/>
</changeSet>
<changeSet id="2024-11-04-add-enrollment_appointment-missing-fields" author="jrkkp">
<addColumn tableName="enrollment_appointment">
<column name="first_name" type="TEXT" />
Expand All @@ -1078,4 +1042,55 @@
referencedTableName="examiner"
referencedColumnNames="examiner_id"/>
</changeSet>
<changeSet id="2024-11-07-new-examiner_exam_event-table" author="pkoivisto">
<createTable tableName="examiner_exam_event">
<column autoIncrement="true" name="examiner_exam_event_id" type="BIGSERIAL">
<constraints primaryKey="true" primaryKeyName="examiner_exam_event_pkey"/>
</column>
<column name="version" type="INT" defaultValueNumeric="0">
<constraints nullable="false"/>
</column>
<column name="created_by" type="TEXT"/>
<column name="modified_by" type="TEXT"/>
<column name="deleted_by" type="TEXT"/>
<column name="created_at" type="TIMESTAMP WITH TIME ZONE" defaultValueComputed="CURRENT_TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="modified_at" type="TIMESTAMP WITH TIME ZONE" defaultValueComputed="CURRENT_TIMESTAMP">
<constraints nullable="false"/>
</column>
<column name="deleted_at" type="TIMESTAMP WITH TIME ZONE"/>
<column name="date" type="DATE">
<constraints nullable="false"/>
</column>
<column name="examiner_id" type="BIGINT">
<constraints nullable="false" />
</column>
<column name="is_hidden" type="BOOLEAN">
<constraints nullable="false" />
</column>
<column name="registration_closes" type="TIMESTAMP WITH TIME ZONE"/>
<column name="max_participants" type="INT"/>
<column name="municipality_id" type="BIGINT">
<constraints nullable="false" />
</column>
<column name="location" type="TEXT">
<constraints nullable="false" />
</column>
</createTable>
<addForeignKeyConstraint
baseTableName="examiner_exam_event"
baseColumnNames="examiner_id"
constraintName="fk_examiner_exam_event_examiner_id"
referencedTableName="examiner"
referencedColumnNames="examiner_id"
/>
<addForeignKeyConstraint
baseTableName="examiner_exam_event"
baseColumnNames="municipality_id"
constraintName="fk_examiner_exam_event_municipality_id"
referencedTableName="municipality"
referencedColumnNames="municipality_id"
/>
</changeSet>
</databaseChangeLog>

0 comments on commit b022a70

Please sign in to comment.