Skip to content

Commit 70a3ee3

Browse files
authored
feat: add communication metadata (#209)
* feat: add communication metadata * test: check if survey-unit is deleted when metadata are linked * fix: use same type in FK, H2 silently casting type is dangerous ⚠️
1 parent 6405148 commit 70a3ee3

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>fr.insee.pearljam</groupId>
99
<artifactId>pearljam-back-office</artifactId>
10-
<version>5.4.0</version>
10+
<version>5.5.0</version>
1111
<name>Pearl-Jam-Back-Office</name>
1212
<description>Back-office services for PearlJam</description>
1313

src/main/java/fr/insee/pearljam/api/domain/SurveyUnit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import fr.insee.pearljam.infrastructure.surveyunit.entity.CommentDB;
1010
import fr.insee.pearljam.infrastructure.surveyunit.entity.CommunicationRequestDB;
1111
import fr.insee.pearljam.infrastructure.surveyunit.entity.ContactOutcomeDB;
12+
import fr.insee.pearljam.infrastructure.surveyunit.entity.CommunicationMetadataDB;
1213
import fr.insee.pearljam.infrastructure.surveyunit.entity.identification.IdentificationDB;
1314
import jakarta.persistence.*;
1415
import lombok.Getter;
@@ -123,6 +124,9 @@ public class SurveyUnit implements Serializable {
123124
@OneToMany(fetch = FetchType.LAZY, targetEntity = CommunicationRequestDB.class, cascade = CascadeType.ALL, mappedBy = "surveyUnit", orphanRemoval = true)
124125
private Set<CommunicationRequestDB> communicationRequests = new HashSet<>();
125126

127+
@OneToMany(fetch = FetchType.LAZY, targetEntity = CommunicationMetadataDB.class, cascade = CascadeType.ALL, mappedBy = "surveyUnit", orphanRemoval = true)
128+
private Set<CommunicationMetadataDB> communicationMetadata = new HashSet<>();
129+
126130
public SurveyUnit(String id, boolean priority, boolean viewed, Address address, SampleIdentifier sampleIdentifier,
127131
Campaign campaign, Interviewer interviewer, OrganizationUnit organizationUnit, Set<Person> persons) {
128132
super();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fr.insee.pearljam.infrastructure.surveyunit.entity;
2+
3+
import fr.insee.pearljam.api.domain.SurveyUnit;
4+
import fr.insee.pearljam.infrastructure.campaign.entity.CommunicationTemplateDB;
5+
import jakarta.persistence.*;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
10+
import java.io.Serializable;
11+
12+
@Entity(name = "communication_metadata")
13+
@Table
14+
@Getter
15+
@Setter
16+
@NoArgsConstructor
17+
public class CommunicationMetadataDB implements Serializable {
18+
@Id
19+
@GeneratedValue(strategy = GenerationType.IDENTITY)
20+
private Long id;
21+
@ManyToOne(fetch = FetchType.LAZY)
22+
private SurveyUnit surveyUnit;
23+
@ManyToOne(fetch = FetchType.LAZY)
24+
private CommunicationTemplateDB communicationTemplate;
25+
@Column(name = "metadata_key")
26+
private String key;
27+
@Column(name = "metadata_value")
28+
private String value;
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
5+
<changeSet author="simondmz" id="580-1">
6+
<createTable tableName="communication_metadata">
7+
<column name="id" type="BIGINT" autoIncrement="true">
8+
<constraints primaryKey="true" primaryKeyName="communication_metadataPK"/>
9+
</column>
10+
<column name="survey_unit_id" type="VARCHAR(255)">
11+
<constraints nullable="false"/>
12+
</column>
13+
<column name="communication_template_id" type="BIGINT">
14+
<constraints nullable="false"/>
15+
</column>
16+
<column name="metadata_key" type="VARCHAR(255)">
17+
<constraints nullable="false"/>
18+
</column>
19+
<column name="metadata_value" type="VARCHAR(255)">
20+
<constraints nullable="false"/>
21+
</column>
22+
</createTable>
23+
<addForeignKeyConstraint
24+
baseTableName="communication_metadata"
25+
baseColumnNames="survey_unit_id"
26+
constraintName="fk_survey_unit"
27+
referencedTableName="survey_unit"
28+
referencedColumnNames="id"/>
29+
<addForeignKeyConstraint
30+
baseTableName="communication_metadata"
31+
baseColumnNames="communication_template_id"
32+
constraintName="fk_communication_template"
33+
referencedTableName="communication_template"
34+
referencedColumnNames="id"/>
35+
</changeSet>
36+
</databaseChangeLog>

src/main/resources/db/dataset/reinit-test-data.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,8 @@ INSERT INTO public.communication_request_status (communication_request_id, statu
222222
(3, 'INITIATED', 1721903754205),
223223
(4, 'INITIATED', 1721903754205);
224224

225+
INSERT INTO public.communication_metadata (survey_unit_id, communication_template_id, metadata_key, metadata_value) VALUES
226+
('11',SELECT ct.id FROM communication_template ct WHERE ct.meshuggah_id='mesh1','recipient_full_name', 'Albert Einstein'),
227+
('11', SELECT ct.id FROM communication_template ct WHERE ct.meshuggah_id='mesh1','recipient_address', '112 Mercer Street, Princeton, New Jersey');
228+
225229
SET REFERENTIAL_INTEGRITY TRUE;

src/main/resources/db/master.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@
8181
<!-- contactOutcome deprecated values removal -->
8282
<include file="changelog/570_remove_unused_contact_outcome_entries.xml" relativeToChangelogFile="true"/>
8383

84+
<!-- add communication metadata -->
85+
<include file="changelog/580_add_communication_metadata.xml" relativeToChangelogFile="true"/>
86+
8487
</databaseChangeLog>

0 commit comments

Comments
 (0)