Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: payload ordering #429

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,6 +60,5 @@ public InformationSubmission(
@JoinColumn(name = "negotiation_id")
private Negotiation negotiation;

@JdbcTypeCode(SqlTypes.JSON)
private String payload;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,9 +198,9 @@

private static @NonNull Set<String> generatedHeadersFromResponses(
List<InformationSubmission> submissions, ObjectMapper objectMapper) {
Set<String> jsonKeys = new TreeSet<>();
Set<String> jsonKeys = new LinkedHashSet<>();

Check warning on line 201 in src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmissionServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/eu/bbmri_eric/negotiator/info_submission/InformationSubmissionServiceImpl.java#L201

Added line #L201 was not covered by tests
for (InformationSubmission submission : submissions) {
JsonNode payload = null;
JsonNode payload;
try {
payload = objectMapper.readTree(submission.getPayload());
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,10 +79,9 @@ public class Negotiation extends AuditEntity {
@Exclude
private Set<Request> 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;
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/db/migration/V14.0__change_payload.sql
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading