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

Change knelpunten_meerkeuze to array #170

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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 @@ -22,10 +22,15 @@
import org.locationtech.jts.io.WKBWriter;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;
import org.postgresql.jdbc.PgArray;
import org.springframework.context.annotation.Profile;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SimplePropertyRowMapper;
import org.springframework.jdbc.core.simple.JdbcClient;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -38,12 +43,24 @@ public class PlanmonitorWonenDatabaseService {
public PlanmonitorWonenDatabaseService(JdbcClient jdbcClient) {
this.jdbcClient = jdbcClient;

final GenericConversionService conversionService = new GenericConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addConverter(
(Converter<PgArray, String[]>)
source -> {
try {
return (String[]) source.getArray();
} catch (SQLException e) {
throw new RuntimeException(e);
}
});

planregistratieRowMapper =
new SimplePropertyRowMapper<>(Planregistratie.class) {
new SimplePropertyRowMapper<>(Planregistratie.class, conversionService) {
@Override
public Planregistratie mapRow(ResultSet rs, int rowNumber) throws SQLException {
@NonNull
public Planregistratie mapRow(@NonNull ResultSet rs, int rowNumber) throws SQLException {
Planregistratie planregistratie = super.mapRow(rs, rowNumber);
assert planregistratie != null;
planregistratie.setGeometrie(wkbToWkt(planregistratie.getGeometrie()));
return planregistratie;
}
Expand Down Expand Up @@ -126,8 +143,8 @@ insert into planregistratie(
aantal_studentenwoningen,
sleutelproject
)
values (%s)"""
.formatted(sqlQuestionMarks(23));
values (%s, ?::pmw_knelpunten_meerkeuze[], %s)"""
.formatted(sqlQuestionMarks(19), sqlQuestionMarks(3));
this.jdbcClient
.sql(insertPlanregistratie)
.param(1, planregistratie.getId(), Types.OTHER)
Expand All @@ -149,7 +166,7 @@ insert into planregistratie(
.param(planregistratie.getBestemmingsplan())
.param(18, planregistratie.getStatusProject(), Types.OTHER)
.param(19, planregistratie.getStatusPlanologisch(), Types.OTHER)
.param(20, planregistratie.getKnelpuntenMeerkeuze(), Types.OTHER)
.param(20, planregistratie.getKnelpuntenMeerkeuze(), Types.ARRAY)
.param(21, planregistratie.getBeoogdWoonmilieuAbf13(), Types.OTHER)
.param(planregistratie.getAantalStudentenwoningen())
.param(planregistratie.isSleutelproject())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void init() throws ParseException {
.setBestemmingsplan("Een bestemmingsplan")
.setStatusProject("Voorbereiding")
.setStatusPlanologisch("3. In voorbereiding")
.setKnelpuntenMeerkeuze("Bereikbaarheid")
.setKnelpuntenMeerkeuze(new String[] {"Bereikbaarheid"})
.setBeoogdWoonmilieuAbf13("Centrum")
.setAantalStudentenwoningen(70)
.setSleutelproject(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class Planregistratie {
private String bestemmingsplan;
private String statusProject;
private String statusPlanologisch;
private String knelpuntenMeerkeuze;
private String[] knelpuntenMeerkeuze;
private String beoogdWoonmilieuAbf13;
private Integer aantalStudentenwoningen;
private boolean sleutelproject;
Expand Down Expand Up @@ -209,11 +209,11 @@ public Planregistratie setStatusPlanologisch(String statusPlanologisch) {
return this;
}

public String getKnelpuntenMeerkeuze() {
public String[] getKnelpuntenMeerkeuze() {
return knelpuntenMeerkeuze;
}

public Planregistratie setKnelpuntenMeerkeuze(String knelpuntenMeerkeuze) {
public Planregistratie setKnelpuntenMeerkeuze(String[] knelpuntenMeerkeuze) {
this.knelpuntenMeerkeuze = knelpuntenMeerkeuze;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table planregistratie alter column knelpunten_meerkeuze
type pmw_knelpunten_meerkeuze[]
using case when knelpunten_meerkeuze is null then array[]::pmw_knelpunten_meerkeuze[] else array[knelpunten_meerkeuze] end;
Loading