diff --git a/src/main/java/de/avatic/lcc/repositories/NodeRepository.java b/src/main/java/de/avatic/lcc/repositories/NodeRepository.java index 87a7828..ec95252 100644 --- a/src/main/java/de/avatic/lcc/repositories/NodeRepository.java +++ b/src/main/java/de/avatic/lcc/repositories/NodeRepository.java @@ -320,9 +320,12 @@ public class NodeRepository { FROM node WHERE node.external_mapping_id = ?"""; - var node = jdbcTemplate.queryForObject(query, new NodeMapper(), mappingId); + var node = jdbcTemplate.query(query, new NodeMapper(), mappingId); - return Optional.ofNullable(node); + if(node.isEmpty()) + return Optional.empty(); + + return Optional.of(node.getFirst()); } diff --git a/src/main/java/de/avatic/lcc/repositories/country/CountryRepository.java b/src/main/java/de/avatic/lcc/repositories/country/CountryRepository.java index 2bacf57..aa7b4d6 100644 --- a/src/main/java/de/avatic/lcc/repositories/country/CountryRepository.java +++ b/src/main/java/de/avatic/lcc/repositories/country/CountryRepository.java @@ -152,7 +152,7 @@ public class CountryRepository { String sql = "SELECT * FROM country WHERE iso_code IN (:isoCodes)"; MapSqlParameterSource parameters = new MapSqlParameterSource(); - parameters.addValue("isoCodes", outboundCountries); + parameters.addValue("isoCodes", outboundCountries.stream().map(Enum::name).toList()); return namedParameterJdbcTemplate.query(sql, parameters, new CountryMapper()); } diff --git a/src/main/java/de/avatic/lcc/service/bulk/helper/ConstraintGenerator.java b/src/main/java/de/avatic/lcc/service/bulk/helper/ConstraintGenerator.java index 32f15ea..4be7001 100644 --- a/src/main/java/de/avatic/lcc/service/bulk/helper/ConstraintGenerator.java +++ b/src/main/java/de/avatic/lcc/service/bulk/helper/ConstraintGenerator.java @@ -209,9 +209,13 @@ public class ConstraintGenerator { } - public void validateStringCell(Row row, int columnIdx) { + public void validateStringCell(Row row, int columnIdx, Boolean allowEmpty) { CellType cellType = row.getCell(columnIdx).getCellType(); + if(cellType == CellType.BLANK && allowEmpty) { + return; + } + if (cellType == CellType.STRING) { String value = row.getCell(columnIdx).getStringCellValue(); @@ -222,6 +226,10 @@ public class ConstraintGenerator { } + public void validateStringCell(Row row, int columnIdx) { + validateStringCell(row, columnIdx, false); + } + public void validateIntegerConstraint(Row row, int columnIdx, int min, int max) { CellType cellType = row.getCell(columnIdx).getCellType(); diff --git a/src/main/java/de/avatic/lcc/service/excelMapper/NodeExcelMapper.java b/src/main/java/de/avatic/lcc/service/excelMapper/NodeExcelMapper.java index 3a87b17..655f563 100644 --- a/src/main/java/de/avatic/lcc/service/excelMapper/NodeExcelMapper.java +++ b/src/main/java/de/avatic/lcc/service/excelMapper/NodeExcelMapper.java @@ -127,8 +127,8 @@ public class NodeExcelMapper { constraintGenerator.validateStringCell(row, NodeHeader.MAPPING_ID.ordinal()); constraintGenerator.validateStringCell(row, NodeHeader.COUNTRY.ordinal()); - constraintGenerator.validateStringCell(row, NodeHeader.OUTBOUND_COUNTRIES.ordinal()); - constraintGenerator.validateStringCell(row, NodeHeader.PREDECESSOR_NODES.ordinal()); + constraintGenerator.validateStringCell(row, NodeHeader.OUTBOUND_COUNTRIES.ordinal(), true); + constraintGenerator.validateStringCell(row, NodeHeader.PREDECESSOR_NODES.ordinal(), true); constraintGenerator.validateStringCell(row, NodeHeader.NAME.ordinal()); constraintGenerator.validateStringCell(row, NodeHeader.ADDRESS.ordinal()); diff --git a/src/main/resources/master_data/01-properties.sql b/src/main/resources/master_data/01-properties.sql index 8f67036..8c8e696 100644 --- a/src/main/resources/master_data/01-properties.sql +++ b/src/main/resources/master_data/01-properties.sql @@ -5,6 +5,10 @@ -- Description -> name -- =================================================== +INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( '2_Reference route: Port of origin', 'START_REF', 'TEXT', '{}','2_Reference route used to demonstrate sea freight fluctuation, port in country of origin','2_Reference route','1'); +INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( '2_Reference route: Port of destination', 'END_REF', 'TEXT', '{}','2_Reference route used to demonstrate sea freight fluctuation, port in country of destination','2_Reference route','2'); +INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( 'All-time-high container rate (40 ft.) [EUR]', 'RISK_REF', 'CURRENCY', '{"GT":0}','Highest container rate to be used to demonstrate sea freight fluctuation, cost for 40 Ft. (FEU) general purpose container','2_Reference route','3'); +INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( 'All-time-low container rate (40 ft.) [EUR]', 'CHANCE_REF', 'CURRENCY', '{"GT":0}','Lowest container rate to be used to demonstrate sea freight fluctuation, cost for 40 Ft. (FEU) general purpose container','2_Reference route','4'); INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( 'Payment terms [days]', 'PAYMENT_TERMS', 'INT', '{}','Payment terms [days] agreed with suppliers.','1_General','3'); INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( 'Annual working days', 'WORKDAYS', 'INT', '{"GT": 0, "LT": 366}','Annual production working days.','1_General','2'); INSERT INTO system_property_type ( name, external_mapping_id, data_type, validation_rule, description, property_group, sequence_number) VALUES ( 'Interest rate inventory [%]', 'INTEREST_RATE', 'PERCENTAGE', '{"GTE": 0}','Interest rate for inventories and payment terms.','1_General','4'); diff --git a/src/main/resources/master_data/07-packaging.sql b/src/main/resources/master_data/07-packaging.sql index b6f15be..f3ac7b6 100644 --- a/src/main/resources/master_data/07-packaging.sql +++ b/src/main/resources/master_data/07-packaging.sql @@ -4,11 +4,11 @@ -- Zuerst die packaging_property_types für stackable und rust prevention erstellen -- (falls sie noch nicht existieren) -INSERT INTO packaging_property_type (name, external_mapping_id, data_type, validation_rule, is_required) +INSERT INTO packaging_property_type (name, external_mapping_id, data_type, validation_rule, is_required, description, property_group, sequence_number) VALUES - ('Stackable', 'STACKABLE', 'BOOLEAN', NULL, FALSE), - ('Rust Prevention', 'RUST_PREVENTION', 'BOOLEAN', NULL, FALSE), - ('Mixable', 'MIXABLE', 'BOOLEAN', NULL, FALSE) + ('Stackable', 'STACKABLE', 'BOOLEAN', NULL, FALSE, 'desc', 'general', 1), + ('Rust Prevention', 'RUST_PREVENTION', 'BOOLEAN', NULL, FALSE, 'desc', 'general', 2), + ('Mixable', 'MIXABLE', 'BOOLEAN', NULL, FALSE, 'desc', 'general', 3) ON DUPLICATE KEY UPDATE name = VALUES(name), data_type = VALUES(data_type); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 242ef87..481a821 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -52,9 +52,6 @@ CREATE TABLE IF NOT EXISTS `country` `iso_code` CHAR(2) NOT NULL COMMENT 'ISO 3166-1 alpha-2 country code', `region_code` CHAR(5) NOT NULL COMMENT 'Geographic region code (EMEA/LATAM/APAC/NAM)', `name` VARCHAR(255) NOT NULL, - `description` VARCHAR(255) NOT NULL, - `property_group` VARCHAR(32) NOT NULL, - `sequence_number` INT NOT NULL, `is_deprecated` BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (`id`), UNIQUE KEY `uk_country_iso_code` (`iso_code`), @@ -69,6 +66,9 @@ CREATE TABLE IF NOT EXISTS `country_property_type` `external_mapping_id` VARCHAR(16), `data_type` VARCHAR(16) NOT NULL, `validation_rule` VARCHAR(64), + `description` VARCHAR(255) NOT NULL, + `property_group` VARCHAR(32) NOT NULL, + `sequence_number` INT NOT NULL, `is_required` BOOLEAN NOT NULL DEFAULT FALSE, CONSTRAINT `chk_country_data_type_values` CHECK (`data_type` IN ('INT', 'PERCENTAGE', 'BOOLEAN', 'CURRENCY', 'ENUMERATION', @@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS `sys_user_node` -- logistic nodes CREATE TABLE IF NOT EXISTS node ( - id INT PRIMARY KEY, + id INT AUTO_INCREMENT PRIMARY KEY, country_id INT NOT NULL, name VARCHAR(255) NOT NULL, address VARCHAR(500) NOT NULL, diff --git a/src/test/resources/master_data/material_packaging.sql b/src/test/resources/master_data/material_packaging.sql index fc25359..17f8c20 100644 --- a/src/test/resources/master_data/material_packaging.sql +++ b/src/test/resources/master_data/material_packaging.sql @@ -60,10 +60,11 @@ VALUES ('28523500576', '028523500576', '85015230', 'traction motor assy. ''AE35- -- Zuerst die packaging_property_types für stackable und rust prevention erstellen -- (falls sie noch nicht existieren) -INSERT INTO packaging_property_type (name, external_mapping_id, data_type, validation_rule, is_required) +INSERT INTO packaging_property_type (name, external_mapping_id, data_type, validation_rule, is_required, description, property_group, sequence_number) VALUES - ('Stackable', 'STACKABLE', 'BOOLEAN', NULL, FALSE), - ('Rust Prevention', 'RUST_PREVENTION', 'BOOLEAN', NULL, FALSE) + ('Stackable', 'STACKABLE', 'BOOLEAN', NULL, FALSE, 'desc', 'general', 1), + ('Rust Prevention', 'RUST_PREVENTION', 'BOOLEAN', NULL, FALSE, 'desc', 'general', 2), + ('Mixable', 'MIXABLE', 'BOOLEAN', NULL, FALSE, 'desc', 'general', 3) ON DUPLICATE KEY UPDATE name = VALUES(name), data_type = VALUES(data_type);