Skip to content

Commit

Permalink
feat: add communication metadata (#209)
Browse files Browse the repository at this point in the history
* 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 ⚠️
  • Loading branch information
SimonDmz authored Feb 28, 2025
1 parent 6405148 commit 70a3ee3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>fr.insee.pearljam</groupId>
<artifactId>pearljam-back-office</artifactId>
<version>5.4.0</version>
<version>5.5.0</version>
<name>Pearl-Jam-Back-Office</name>
<description>Back-office services for PearlJam</description>

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/insee/pearljam/api/domain/SurveyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fr.insee.pearljam.infrastructure.surveyunit.entity.CommentDB;
import fr.insee.pearljam.infrastructure.surveyunit.entity.CommunicationRequestDB;
import fr.insee.pearljam.infrastructure.surveyunit.entity.ContactOutcomeDB;
import fr.insee.pearljam.infrastructure.surveyunit.entity.CommunicationMetadataDB;
import fr.insee.pearljam.infrastructure.surveyunit.entity.identification.IdentificationDB;
import jakarta.persistence.*;
import lombok.Getter;
Expand Down Expand Up @@ -123,6 +124,9 @@ public class SurveyUnit implements Serializable {
@OneToMany(fetch = FetchType.LAZY, targetEntity = CommunicationRequestDB.class, cascade = CascadeType.ALL, mappedBy = "surveyUnit", orphanRemoval = true)
private Set<CommunicationRequestDB> communicationRequests = new HashSet<>();

@OneToMany(fetch = FetchType.LAZY, targetEntity = CommunicationMetadataDB.class, cascade = CascadeType.ALL, mappedBy = "surveyUnit", orphanRemoval = true)
private Set<CommunicationMetadataDB> communicationMetadata = new HashSet<>();

public SurveyUnit(String id, boolean priority, boolean viewed, Address address, SampleIdentifier sampleIdentifier,
Campaign campaign, Interviewer interviewer, OrganizationUnit organizationUnit, Set<Person> persons) {
super();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fr.insee.pearljam.infrastructure.surveyunit.entity;

import fr.insee.pearljam.api.domain.SurveyUnit;
import fr.insee.pearljam.infrastructure.campaign.entity.CommunicationTemplateDB;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Entity(name = "communication_metadata")
@Table
@Getter
@Setter
@NoArgsConstructor
public class CommunicationMetadataDB implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private SurveyUnit surveyUnit;
@ManyToOne(fetch = FetchType.LAZY)
private CommunicationTemplateDB communicationTemplate;
@Column(name = "metadata_key")
private String key;
@Column(name = "metadata_value")
private String value;
}
36 changes: 36 additions & 0 deletions src/main/resources/db/changelog/580_add_communication_metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="simondmz" id="580-1">
<createTable tableName="communication_metadata">
<column name="id" type="BIGINT" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="communication_metadataPK"/>
</column>
<column name="survey_unit_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="communication_template_id" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="metadata_key" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="metadata_value" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
</createTable>
<addForeignKeyConstraint
baseTableName="communication_metadata"
baseColumnNames="survey_unit_id"
constraintName="fk_survey_unit"
referencedTableName="survey_unit"
referencedColumnNames="id"/>
<addForeignKeyConstraint
baseTableName="communication_metadata"
baseColumnNames="communication_template_id"
constraintName="fk_communication_template"
referencedTableName="communication_template"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>
4 changes: 4 additions & 0 deletions src/main/resources/db/dataset/reinit-test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,8 @@ INSERT INTO public.communication_request_status (communication_request_id, statu
(3, 'INITIATED', 1721903754205),
(4, 'INITIATED', 1721903754205);

INSERT INTO public.communication_metadata (survey_unit_id, communication_template_id, metadata_key, metadata_value) VALUES
('11',SELECT ct.id FROM communication_template ct WHERE ct.meshuggah_id='mesh1','recipient_full_name', 'Albert Einstein'),
('11', SELECT ct.id FROM communication_template ct WHERE ct.meshuggah_id='mesh1','recipient_address', '112 Mercer Street, Princeton, New Jersey');

SET REFERENTIAL_INTEGRITY TRUE;
3 changes: 3 additions & 0 deletions src/main/resources/db/master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@
<!-- contactOutcome deprecated values removal -->
<include file="changelog/570_remove_unused_contact_outcome_entries.xml" relativeToChangelogFile="true"/>

<!-- add communication metadata -->
<include file="changelog/580_add_communication_metadata.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>

0 comments on commit 70a3ee3

Please sign in to comment.