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

Do variable renaming regarding export feature #136

Merged
merged 1 commit into from
Jan 9, 2024
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 @@ -32,10 +32,10 @@ public ImporterLine mapRow(final ResultSet resultSet, final int rowNumber) throw
return ImporterLine.of(
ExternalId.of(resultSet.getString("external_id")),
resultSet.getString("line_number"),
jsonConverter.fromJson(resultSet.getString("name"), MultilingualString.class),
jsonConverter.fromJson(resultSet.getString("line_header_name"), MultilingualString.class),
NetworkType.of(resultSet.getString("network_type")),
jsonConverter.fromJson(resultSet.getString("short_name"), MultilingualString.class),
DATE_RANGE_CONVERTER.from(resultSet.getString("valid_date_range")),
jsonConverter.fromJson(resultSet.getString("line_header_short_name"), MultilingualString.class),
DATE_RANGE_CONVERTER.from(resultSet.getString("line_header_valid_date_range")),
TypeOfLine.of(resultSet.getString("type_of_line")),
LegacyHslMunicipalityCode.valueOf(resultSet.getString("legacy_hsl_municipality_code"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Jore4Line process(final ImporterLine input) throws Exception {

return Jore4Line.of(
UUID.randomUUID(),
input.externalId().value(),
input.externalIdOfLine().value(),
input.lineNumber(),
input.name(),
input.shortName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void write(final List<? extends Jore4Line> items) throws Exception {

final io.vavr.collection.List<PersistableLineIdMapping> jore4IdMappings = items.stream()
.map(item -> PersistableLineIdMapping.of(
item.externalLineId(),
item.externalIdOfLine(),
item.lineId()
))
.collect(io.vavr.collection.List.collector());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public void setJore4Ids(final List<PersistableLineIdMapping> idMappings) {
db.batched(c -> {
idMappings.forEach(idMapping -> {
c.dsl().update(TARGET_TABLE)
.set(TARGET_TABLE.NETWORK_LINE_JORE4_ID, idMapping.jore4Id())
.where(TARGET_TABLE.NETWORK_LINE_EXT_ID.eq(idMapping.externalId()))
.set(TARGET_TABLE.NETWORK_LINE_JORE4_ID, idMapping.jore4IdOfLine())
.where(TARGET_TABLE.NETWORK_LINE_EXT_ID.eq(idMapping.externalIdOfLine()))
.execute();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ImporterRoute mapRow(final ResultSet resultSet, final int rowNumber) thro
UUID.fromString(resultSet.getString("direction_id")),
DirectionType.of(resultSet.getString("direction_type")),
jsonConverter.fromJson(resultSet.getString("name"), MultilingualString.class),
UUID.fromString(resultSet.getString("line_jore4_id")),
UUID.fromString(resultSet.getString("jore4_id_of_line")),
DATE_RANGE_CONVERTER.from(resultSet.getString("valid_date_range")),
LegacyHslMunicipalityCode.valueOf(resultSet.getString("legacy_hsl_municipality_code"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Jore4Route process(final ImporterRoute input) throws Exception {
input.directionId(),
input.routeNumber(),
input.hiddenVariant(),
input.lineJore4Id(),
input.jore4IdOfLine(),
DEFAULT_PRIORITY,
ValidityPeriodUtil.constructValidityPeriodStartDay(input.validDateRange().range()),
ValidityPeriodUtil.constructValidityPeriodEndDay(input.validDateRange().range()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import java.util.UUID;

/**
* Contains the information of a line which can
* inserted into the Jore 4 transmodel schema.
* Contains the information of a line which can inserted into the Jore 4
* Transmodel schema.
*/
@Value.Immutable
public interface Jore4Line {

UUID lineId();

String externalLineId();
String externalIdOfLine();

String label();

Expand All @@ -37,7 +37,7 @@ public interface Jore4Line {
LegacyHslMunicipalityCode legacyHslMunicipalityCode();

static ImmutableJore4Line of(final UUID lineId,
final String externalLineId,
final String externalIdOfLine,
final String label,
final MultilingualString name,
final MultilingualString shortName,
Expand All @@ -49,7 +49,7 @@ static ImmutableJore4Line of(final UUID lineId,
final LegacyHslMunicipalityCode legacyHslMunicipalityCode) {
return ImmutableJore4Line.builder()
.lineId(lineId)
.externalLineId(externalLineId)
.externalIdOfLine(externalIdOfLine)
.label(label)
.name(name)
.shortName(shortName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.immutables.value.Value;

/**
* Contains the information of a line which is required when
* we want to export lines to the Jore 4 transmodel schema.
* Contains the information of a line that is required when
* we want to export lines to the Jore 4 Transmodel schema.
*/
@Value.Immutable
public interface ImporterLine {

ExternalId externalId();
ExternalId externalIdOfLine();

String lineNumber();

Expand All @@ -31,7 +31,7 @@ public interface ImporterLine {

LegacyHslMunicipalityCode legacyHslMunicipalityCode();

static ImmutableImporterLine of (final ExternalId externalId,
static ImmutableImporterLine of (final ExternalId externalIdOfLine,
final String lineNumber,
final MultilingualString name,
final NetworkType networkType,
Expand All @@ -40,7 +40,7 @@ static ImmutableImporterLine of (final ExternalId externalId,
final TypeOfLine typeOfLine,
final LegacyHslMunicipalityCode legacyHslMunicipalityCode) {
return ImmutableImporterLine.builder()
.externalId(externalId)
.externalIdOfLine(externalIdOfLine)
.lineNumber(lineNumber)
.name(name)
.networkType(networkType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
import java.util.UUID;

/**
* Contains the information that's required to update
* the Jore 4 id (primary key of a line found from
* Jore 4 database) of a line stored in the database
* of the importer application.
* Contains the information that's required to update the Jore 4 ID (primary
* key of a line found from the Jore 4 database) of a line stored in the
* database of the importer application.
*/
@Value.Immutable
public interface PersistableLineIdMapping {

String externalId();
String externalIdOfLine();

UUID jore4Id();
UUID jore4IdOfLine();

static PersistableLineIdMapping of(final String externalId,
final UUID jore4Id) {
static PersistableLineIdMapping of(final String externalIdOfLine,
final UUID jore4IdOfLine) {
return ImmutablePersistableLineIdMapping.builder()
.externalId(externalId)
.jore4Id(jore4Id)
.externalIdOfLine(externalIdOfLine)
.jore4IdOfLine(jore4IdOfLine)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.util.UUID;

/**
* Contains the source data of a route which is exported
* to the Jore 4 database.
* Contains the source data of a route which is exported to the Jore 4 database.
*/
@Value.Immutable
public interface ImporterRoute {
Expand All @@ -22,7 +21,7 @@ public interface ImporterRoute {

MultilingualString name();

UUID lineJore4Id();
UUID jore4IdOfLine();

String routeNumber();

Expand All @@ -37,14 +36,14 @@ static ImporterRoute of(final String routeNumber,
final UUID directionId,
final DirectionType directionType,
final MultilingualString name,
final UUID lineJore4Id,
final UUID jore4IdOfLine,
final DateRange validDateRange,
final LegacyHslMunicipalityCode legacyHslMunicipalityCode) {
return ImmutableImporterRoute.builder()
.directionId(directionId)
.directionType(directionType)
.name(name)
.lineJore4Id(lineJore4Id)
.jore4IdOfLine(jore4IdOfLine)
.routeNumber(routeNumber)
.hiddenVariant(hiddenVariant)
.validDateRange(validDateRange)
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/jore4-export/export_lines.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ SELECT
l.infrastructure_network_type AS network_type,
l.network_line_type_of_line AS type_of_line,
l.network_line_legacy_hsl_municipality_code AS legacy_hsl_municipality_code,
lh.network_line_header_name AS name,
lh.network_line_header_name_short AS short_name,
lh.network_line_header_valid_date_range AS valid_date_range
lh.network_line_header_name AS line_header_name,
lh.network_line_header_name_short AS line_header_short_name,
lh.network_line_header_valid_date_range AS line_header_valid_date_range
FROM network.network_lines l
JOIN network.network_line_headers lh USING (network_line_id)
WHERE
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/jore4-export/export_routes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SELECT
rd.network_route_direction_id AS direction_id,
rd.network_route_direction_type AS direction_type,
rd.network_route_direction_name AS name,
l.network_line_jore4_id AS line_jore4_id,
l.network_line_jore4_id AS jore4_id_of_line,
rd.network_route_direction_valid_date_range AS valid_date_range,
r.network_route_legacy_hsl_municipality_code AS legacy_hsl_municipality_code
FROM network.network_routes r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ExportRouteStepTest extends BatchIntegrationTest {
private static final List<String> STEPS = List.of("exportRoutesStep");

private final String EXPECTED_DIRECTION = Jore4RouteDirection.INBOUND.getValue();
private final UUID EXPECTED_LINE_JORE4_ID = UUID.fromString("5aa7d9fc-2cf9-466d-8ac0-f442d60c261f");
private final UUID EXPECTED_JORE4_ID_OF_LINE = UUID.fromString("5aa7d9fc-2cf9-466d-8ac0-f442d60c261f");
private static final String EXPECTED_LABEL = "1";
private static final String EXPECTED_DESCRIPTION = "{\"fi_FI\":\"Keskustori - Kaleva - Etelä-Hervanta vanha\",\"sv_SE\":\"Central torget - Kaleva - Södra Hervanta gamla\"}";
private static final int EXPECTED_PRIORITY = 10;
Expand Down Expand Up @@ -131,14 +131,14 @@ void shouldSaveExportedRouteWithCorrectLabel() {
}

@Test
@DisplayName("Should save the exported route with the correct line id")
@DisplayName("Should save the exported route with the correct line ID")
void shouldSaveExportedRouteWithCorrectLineId() {
runSteps(STEPS);

assertThat(jore4TargetTable)
.row()
.value(JORE4_ROUTE.ON_LINE_ID.getName())
.isEqualTo(EXPECTED_LINE_JORE4_ID);
.isEqualTo(EXPECTED_JORE4_ID_OF_LINE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class LineExportProcessorTest {

private static final String LINE_NUMBER = "35";
private static final String EXTERNAL_ID = "7863";
private static final String EXTERNAL_ID_OF_LINE = "7863";
private static final String FINNISH_NAME = "Vantaanportti-Lentoasema-Kerava";
private static final String FINNISH_SHORT_NAME = "Vantaanp-Kerava";
private static final String SWEDISH_NAME = "Vandaporten-Flygstationen-Kervo";
Expand All @@ -36,7 +36,7 @@ class LineExportProcessorTest {
private static final int EXPECTED_PRIORITY = 10;

private static final ImporterLine INPUT = ImporterLine.of(
ExternalId.of(EXTERNAL_ID),
ExternalId.of(EXTERNAL_ID_OF_LINE),
LINE_NUMBER,
JoreLocaleUtil.createMultilingualString(FINNISH_NAME, SWEDISH_NAME),
NETWORK_TYPE_ROAD,
Expand All @@ -61,10 +61,10 @@ void shouldReturnLineWithGeneratedId() throws Exception {
}

@Test
@DisplayName("Should return a line with the correct external id")
@DisplayName("Should return a line with the correct external ID")
void shouldReturnLineWithCorrectExternalId() throws Exception {
final Jore4Line line = processor.process(INPUT);
assertThat(line.externalLineId()).isEqualTo(EXTERNAL_ID);
assertThat(line.externalIdOfLine()).isEqualTo(EXTERNAL_ID_OF_LINE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@IntTest
class LineExportReaderTest {

private static final String EXPECTED_EXTERNAL_ID = "1001";
private static final String EXPECTED_EXTERNAL_ID_OF_LINE = "1001";

private static final String EXPECTED_LINE_NUMBER = "1";

Expand Down Expand Up @@ -88,9 +88,9 @@ class WhenSourceTablesHaveOneLine {
void firstInvocationOfReadMethodMustReturnFoundLine(final SoftAssertions softAssertions) throws Exception {
final ImporterLine line = reader.read();

softAssertions.assertThat(line.externalId().value())
.as("externalId")
.isEqualTo(EXPECTED_EXTERNAL_ID);
softAssertions.assertThat(line.externalIdOfLine().value())
.as("externalIdOfLine")
.isEqualTo(EXPECTED_EXTERNAL_ID_OF_LINE);

softAssertions.assertThat(line.lineNumber())
.as("lineNumber")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RouteExportProcessorTest {
private static final int JORE4_ROUTE_PRIORITY = 10;
private static final String FINNISH_NAME = "Keskustori - Etelä-Hervanta";
private static final String SWEDISH_NAME = "Central torget - Södra Hervanta";
private static final UUID LINE_JORE4_ID = UUID.fromString("184b4710-9366-4500-aef3-39d03e95dde2");
private static final UUID JORE4_ID_OF_LINE = UUID.fromString("184b4710-9366-4500-aef3-39d03e95dde2");
private static final String ROUTE_NUMBER = "30";
private static final Optional<Short> ROUTE_HIDDEN_VARIANT = Optional.of((short)1);
private static final LocalDate VALIDITY_PERIOD_START_DAY = LocalDate.of(2021, 1, 1);
Expand All @@ -38,7 +38,7 @@ class RouteExportProcessorTest {
IMPORTER_ROUTE_DIRECTION_ID,
IMPORTER_ROUTE_DIRECTION,
createMultilingualString(FINNISH_NAME, SWEDISH_NAME),
LINE_JORE4_ID,
JORE4_ID_OF_LINE,
DateRange.between(VALIDITY_PERIOD_START_DAY, VALIDITY_PERIOD_END_DAY),
ROUTE_LEGACY_HSL_MUNICIPALITY_CODE
);
Expand Down Expand Up @@ -97,10 +97,10 @@ void shouldReturnRouteWithCorrectHiddenVariantNull() throws Exception {
}

@Test
@DisplayName("Should return a route with the correct line Jore 4 id")
void shouldReturnRouteWithCorrectLineJore4Id() throws Exception {
@DisplayName("Should return a route with the correct Jore 4 ID of line")
void shouldReturnRouteWithCorrectJore4IdOfLine() throws Exception {
final Jore4Route route = processor.process(INPUT);
assertThat(route.lineId()).isEqualTo(LINE_JORE4_ID);
assertThat(route.lineId()).isEqualTo(JORE4_ID_OF_LINE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class WhenSourceTableHasOneRoute {

private final UUID EXPECTED_DIRECTION_ID = UUID.fromString("6f93fa6b-8a19-4b98-bd84-b8409e670c70");
private final DirectionType EXPECTED_DIRECTION_TYPE = DirectionType.INBOUND;
private final UUID EXPECTED_LINE_JORE4_ID = UUID.fromString("5aa7d9fc-2cf9-466d-8ac0-f442d60c261f");
private final UUID EXPECTED_JORE4_ID_OF_LINE = UUID.fromString("5aa7d9fc-2cf9-466d-8ac0-f442d60c261f");
private static final String EXPECTED_ROUTE_NUMBER = "1";
private static final String EXPECTED_FINNISH_NAME = "Keskustori - Kaleva - Etelä-Hervanta vanha";
private static final String EXPECTED_SWEDISH_NAME = "Central torget - Kaleva - Södra Hervanta gamla";
Expand All @@ -93,9 +93,9 @@ void firstInvocationOfReadMethodMustReturnFoundRoute(final SoftAssertions softAs
softAssertions.assertThat(route.directionType())
.as("directionType")
.isEqualTo(EXPECTED_DIRECTION_TYPE);
softAssertions.assertThat(route.lineJore4Id())
.as("lineJore4Id")
.isEqualTo(EXPECTED_LINE_JORE4_ID);
softAssertions.assertThat(route.jore4IdOfLine())
.as("jore4IdOfLine")
.isEqualTo(EXPECTED_JORE4_ID_OF_LINE);
softAssertions.assertThat(route.routeNumber())
.as("routeNumber")
.isEqualTo(EXPECTED_ROUTE_NUMBER);
Expand Down
Loading