diff --git a/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmission.java b/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmission.java index 2a6f2896c..8a99be235 100644 --- a/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmission.java +++ b/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmission.java @@ -11,8 +11,6 @@ import jakarta.persistence.ManyToOne; import lombok.Getter; import lombok.Setter; -import org.hibernate.annotations.JdbcTypeCode; -import org.hibernate.type.SqlTypes; /** Represents a submission of additional information by the resource representative. */ @Setter @@ -62,6 +60,5 @@ public InformationSubmission( @JoinColumn(name = "negotiation_id") private Negotiation negotiation; - @JdbcTypeCode(SqlTypes.JSON) private String payload; } diff --git a/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmissionServiceImpl.java b/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmissionServiceImpl.java index 16b52eff9..fb890964b 100644 --- a/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmissionServiceImpl.java +++ b/src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmissionServiceImpl.java @@ -21,12 +21,12 @@ import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.TreeSet; import lombok.NonNull; import lombok.extern.apachecommons.CommonsLog; import org.apache.commons.csv.CSVFormat; @@ -198,9 +198,9 @@ private static void buildRow( private static @NonNull Set generatedHeadersFromResponses( List submissions, ObjectMapper objectMapper) { - Set jsonKeys = new TreeSet<>(); + Set jsonKeys = new LinkedHashSet<>(); for (InformationSubmission submission : submissions) { - JsonNode payload = null; + JsonNode payload; try { payload = objectMapper.readTree(submission.getPayload()); } catch (JsonProcessingException e) { diff --git a/src/main/java/eu/bbmri_eric/negotiator/negotiation/Negotiation.java b/src/main/java/eu/bbmri_eric/negotiator/negotiation/Negotiation.java index 616c27f48..a7f4b40b6 100644 --- a/src/main/java/eu/bbmri_eric/negotiator/negotiation/Negotiation.java +++ b/src/main/java/eu/bbmri_eric/negotiator/negotiation/Negotiation.java @@ -40,9 +40,7 @@ import lombok.Setter; import lombok.ToString.Exclude; import org.hibernate.annotations.Formula; -import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.annotations.UuidGenerator; -import org.hibernate.type.SqlTypes; @Entity @NoArgsConstructor @@ -81,10 +79,9 @@ public class Negotiation extends AuditEntity { @Exclude private Set requests; - @Formula(value = "JSONB_EXTRACT_PATH_TEXT(payload, 'project', 'title')") + @Formula(value = "JSONB_EXTRACT_PATH_TEXT(payload::jsonb, 'project', 'title')") private String title; - @JdbcTypeCode(SqlTypes.JSON) private String payload; private boolean publicPostsEnabled = true; diff --git a/src/main/resources/db/migration/V14.0__change_payload.sql b/src/main/resources/db/migration/V14.0__change_payload.sql new file mode 100644 index 000000000..003068c71 --- /dev/null +++ b/src/main/resources/db/migration/V14.0__change_payload.sql @@ -0,0 +1,30 @@ +-- 1. Add a new column of type TEXT +ALTER TABLE negotiation + ADD COLUMN payload_text TEXT; + +-- 2. Copy the data from the JSONB column to the new TEXT column +UPDATE negotiation +SET payload_text = payload::TEXT; + +-- 3. Drop the original JSONB column +ALTER TABLE negotiation + DROP COLUMN payload; + +-- 4. Rename the new TEXT column to the original column name +ALTER TABLE negotiation + RENAME COLUMN payload_text TO payload; + +ALTER TABLE information_submission + ADD COLUMN payload_text TEXT; + +-- 2. Copy the data from the JSONB column to the new TEXT column +UPDATE information_submission +SET payload_text = payload::TEXT; + +-- 3. Drop the original JSONB column +ALTER TABLE information_submission + DROP COLUMN payload; + +-- 4. Rename the new TEXT column to the original column name +ALTER TABLE information_submission + RENAME COLUMN payload_text TO payload; diff --git a/src/test/java/eu/bbmri_eric/negotiator/integration/api/v3/InformationRequirementControllerTest.java b/src/test/java/eu/bbmri_eric/negotiator/integration/api/v3/InformationRequirementControllerTest.java index cea0bf7ad..ba3599d9a 100644 --- a/src/test/java/eu/bbmri_eric/negotiator/integration/api/v3/InformationRequirementControllerTest.java +++ b/src/test/java/eu/bbmri_eric/negotiator/integration/api/v3/InformationRequirementControllerTest.java @@ -517,8 +517,8 @@ void generateSummary_1submission_ok() throws Exception { .andExpect(status().isOk()); String expectedResponse = """ -resourceId,num-of-samples,num-of-subjects,sample-type,volume-per-sample -biobank:1:collection:1,20,10,DNA,5 +resourceId,sample-type,num-of-subjects,num-of-samples,volume-per-sample +biobank:1:collection:1,DNA,10,20,5 """; mockMvc .perform(