Refactor packaging and material models for improved clarity
Introduced dedicated classes (`PackagingMaterial`, `MaterialPackaging`, `PackagingSupplier`, `MaterialSupplier`) to better encapsulate packaging and material-related data. Updated repository methods and model references to ensure proper use of the new classes, improving maintainability and reducing ambiguity in the domain model.
This commit is contained in:
parent
2b0ee0d417
commit
631a5c2f53
12 changed files with 379 additions and 109 deletions
|
|
@ -25,7 +25,7 @@ public class Material {
|
|||
@JsonProperty("is_deprecated")
|
||||
private Boolean isDeprecated;
|
||||
|
||||
private PackagingListEntry packaging;
|
||||
private MaterialPackaging packaging;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
|
|
@ -76,11 +76,11 @@ public class Material {
|
|||
isDeprecated = deprecated;
|
||||
}
|
||||
|
||||
public PackagingListEntry getPackaging() {
|
||||
public MaterialPackaging getPackaging() {
|
||||
return packaging;
|
||||
}
|
||||
|
||||
public void setPackaging(PackagingListEntry packaging) {
|
||||
public void setPackaging(MaterialPackaging packaging) {
|
||||
this.packaging = packaging;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package de.avatic.lcc.model.materials;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.avatic.lcc.model.nodes.NodeListEntry;
|
||||
import de.avatic.lcc.model.packaging.PackagingDimension;
|
||||
|
||||
public class MaterialPackaging {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private MaterialSupplier supplier;
|
||||
|
||||
@JsonProperty("handling_unit")
|
||||
private PackagingDimension hu;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public MaterialSupplier getSupplier() {
|
||||
return supplier;
|
||||
}
|
||||
|
||||
public void setSupplier(MaterialSupplier supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
public PackagingDimension getHu() {
|
||||
return hu;
|
||||
}
|
||||
|
||||
public void setHu(PackagingDimension hu) {
|
||||
this.hu = hu;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package de.avatic.lcc.model.materials;
|
||||
|
||||
import de.avatic.lcc.model.country.CountryListEntry;
|
||||
import de.avatic.lcc.model.nodes.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MaterialSupplier {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private CountryListEntry country;
|
||||
private String address;
|
||||
private List<NodeType> types;
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public CountryListEntry getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(CountryListEntry country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public List<NodeType> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(List<NodeType> types) {
|
||||
this.types = types;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,15 +2,43 @@ package de.avatic.lcc.model.nodes;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* Represents the various types of nodes that can exist in the system.
|
||||
* A node can be categorized as SINK, SOURCE, or INTERMEDIATE, depending
|
||||
* on its role within a network or process.
|
||||
*/
|
||||
public enum NodeType {
|
||||
SINK("sink"), SOURCE("source"), INTERMEDIATE("intermediate");
|
||||
/**
|
||||
* Represents a node that consumes resources or products (end-point of flow).
|
||||
*/
|
||||
SINK("sink"),
|
||||
|
||||
/**
|
||||
* Represents a node that originates or provides resources or products for a process.
|
||||
*/
|
||||
SOURCE("source"),
|
||||
|
||||
/**
|
||||
* Represents a node that acts as an intermediary in the flow between a source and a sink.
|
||||
*/
|
||||
INTERMEDIATE("intermediate");
|
||||
|
||||
private final String displayedType;
|
||||
|
||||
/**
|
||||
* Constructs a NodeType instance with its associated displayed type string.
|
||||
*
|
||||
* @param displayedType The string representation of the node type.
|
||||
*/
|
||||
NodeType(String displayedType) {
|
||||
this.displayedType = displayedType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the string representation of this node type, used for serialization.
|
||||
*
|
||||
* @return The string representation of the node type.
|
||||
*/
|
||||
@JsonValue
|
||||
public String getDisplayedType() {
|
||||
return displayedType;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package de.avatic.lcc.model.packaging;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* Represents the supported dimensional units in the system.
|
||||
* This enum is used to specify the unit of measurement for dimensions
|
||||
* in packaging-related classes and operations.
|
||||
* <p>
|
||||
* The supported dimensional units are:
|
||||
* An enumeration representing the units of dimension measurement.
|
||||
*
|
||||
* This enum is used to specify the dimension unit for various entities
|
||||
* such as packaging dimensions and related calculations.
|
||||
*
|
||||
* The supported dimension units are:
|
||||
* - M: Meters
|
||||
* - CM: Centimeters
|
||||
* - MM: Millimeters
|
||||
|
|
@ -49,6 +52,13 @@ public enum DimensionUnit {
|
|||
return valueInBaseUnit / this.baseFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given value from millimeters (MM) to the unit represented by this instance.
|
||||
*
|
||||
* @param value the value in millimeters to convert
|
||||
* @return the converted value in the target unit
|
||||
* @throws IllegalArgumentException if the provided value is null
|
||||
*/
|
||||
public Double convertFromMM(Number value) {
|
||||
return convertFrom(value, MM);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ public class Packaging {
|
|||
@JsonProperty("is_deprecated")
|
||||
private Boolean isDeprecated;
|
||||
|
||||
private NodeListEntry supplier;
|
||||
private PackagingSupplier supplier;
|
||||
|
||||
private MaterialListEntry material;
|
||||
private PackagingMaterial material;
|
||||
|
||||
@JsonProperty("handling_unit")
|
||||
private PackagingDimension hu;
|
||||
|
|
@ -50,19 +50,19 @@ public class Packaging {
|
|||
isDeprecated = deprecated;
|
||||
}
|
||||
|
||||
public NodeListEntry getSupplier() {
|
||||
public PackagingSupplier getSupplier() {
|
||||
return supplier;
|
||||
}
|
||||
|
||||
public void setSupplier(NodeListEntry supplier) {
|
||||
public void setSupplier(PackagingSupplier supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
public MaterialListEntry getMaterial() {
|
||||
public PackagingMaterial getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(MaterialListEntry material) {
|
||||
public void setMaterial(PackagingMaterial material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ public class PackagingListEntry {
|
|||
|
||||
private Integer id;
|
||||
|
||||
private NodeListEntry supplier;
|
||||
private PackagingSupplier supplier;
|
||||
|
||||
private MaterialListEntry material;
|
||||
private PackagingMaterial material;
|
||||
|
||||
@JsonProperty("handling_unit")
|
||||
private PackagingDimension hu;
|
||||
|
|
@ -23,19 +23,19 @@ public class PackagingListEntry {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public NodeListEntry getSupplier() {
|
||||
public PackagingSupplier getSupplier() {
|
||||
return supplier;
|
||||
}
|
||||
|
||||
public void setSupplier(NodeListEntry supplier) {
|
||||
public void setSupplier(PackagingSupplier supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
public MaterialListEntry getMaterial() {
|
||||
public PackagingMaterial getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void setMaterial(MaterialListEntry material) {
|
||||
public void setMaterial(PackagingMaterial material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package de.avatic.lcc.model.packaging;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class PackagingMaterial {
|
||||
|
||||
private Integer id;
|
||||
@JsonProperty("part_number")
|
||||
private String partNumber;
|
||||
private String name;
|
||||
private String hsCode;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPartNumber() {
|
||||
return partNumber;
|
||||
}
|
||||
|
||||
public void setPartNumber(String partNumber) {
|
||||
this.partNumber = partNumber;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getHsCode() {
|
||||
return hsCode;
|
||||
}
|
||||
|
||||
public void setHsCode(String hsCode) {
|
||||
this.hsCode = hsCode;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package de.avatic.lcc.model.packaging;
|
||||
|
||||
import de.avatic.lcc.model.country.CountryListEntry;
|
||||
import de.avatic.lcc.model.nodes.NodeType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PackagingSupplier {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private CountryListEntry country;
|
||||
private String address;
|
||||
private List<NodeType> types;
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public CountryListEntry getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(CountryListEntry country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public List<NodeType> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(List<NodeType> types) {
|
||||
this.types = types;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,17 @@
|
|||
package de.avatic.lcc.model.packaging;
|
||||
|
||||
|
||||
/**
|
||||
* Represents the type of packaging used in the system.
|
||||
* This enum defines two types of packaging:
|
||||
*
|
||||
* - SHU: Small Handling Unit.
|
||||
* - HU: Handling Unit.
|
||||
*
|
||||
* It is commonly utilized in packaging-related entities such as
|
||||
* {@link PackagingDimension} to specify the type
|
||||
* of a particular packaging instance.
|
||||
*/
|
||||
public enum PackagingType {
|
||||
SHU, HU
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ package de.avatic.lcc.repositories;
|
|||
import de.avatic.lcc.model.country.CountryListEntry;
|
||||
import de.avatic.lcc.model.materials.Material;
|
||||
import de.avatic.lcc.model.materials.MaterialListEntry;
|
||||
import de.avatic.lcc.model.materials.MaterialPackaging;
|
||||
import de.avatic.lcc.model.materials.MaterialSupplier;
|
||||
import de.avatic.lcc.model.nodes.NodeListEntry;
|
||||
import de.avatic.lcc.model.packaging.DimensionUnit;
|
||||
import de.avatic.lcc.model.packaging.PackagingListEntry;
|
||||
import de.avatic.lcc.model.packaging.WeightUnit;
|
||||
import de.avatic.lcc.model.nodes.NodeType;
|
||||
import de.avatic.lcc.model.packaging.*;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -18,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
|
|
@ -32,15 +34,15 @@ public class MaterialRepository {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public SearchQueryResult<MaterialListEntry> listMaterials(String filter, SearchQueryPagination pagination) {
|
||||
public SearchQueryResult<MaterialListEntry> listMaterials(String filter, boolean excludeDeprecated, SearchQueryPagination pagination) {
|
||||
String query = "SELECT id, name, part_number FROM material WHERE name LIKE ? OR part_number LIKE ? LIMIT ? OFFSET ?";
|
||||
|
||||
var entries = jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
MaterialListEntry entry = new MaterialListEntry();
|
||||
entry.setId(rs.getInt("id"));
|
||||
entry.setName(rs.getString("name"));
|
||||
entry.setPartNumber(rs.getString("part_number"));
|
||||
return entry;
|
||||
var materials = jdbcTemplate.query(query, (rs, rowNum) -> {
|
||||
MaterialListEntry data = new MaterialListEntry();
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setName(rs.getString("name"));
|
||||
data.setPartNumber(rs.getString("part_number"));
|
||||
return data;
|
||||
}, "%" + filter + "%", "%" + filter + "%", pagination.getLimit(), pagination.getOffset());
|
||||
|
||||
Integer totalCount = jdbcTemplate.queryForObject(
|
||||
|
|
@ -48,86 +50,118 @@ public class MaterialRepository {
|
|||
Integer.class, "%" + filter + "%", "%" + filter + "%"
|
||||
);
|
||||
|
||||
return new SearchQueryResult<>(entries, totalCount, pagination.getLimit(), pagination.getOffset());
|
||||
return new SearchQueryResult<>(materials, totalCount, pagination.getLimit(), pagination.getOffset());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Transactional
|
||||
public Optional<Material> getById(Integer id) {
|
||||
String query = "SELECT * FROM material WHERE id = ? AND is_deprecated = FALSE";
|
||||
|
||||
Material material = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
Material foundMaterial = new Material();
|
||||
foundMaterial.setId(rs.getInt("id"));
|
||||
foundMaterial.setName(rs.getString("name"));
|
||||
foundMaterial.setPartNumber(rs.getString("part_number"));
|
||||
foundMaterial.setNormalizedPartNumber(rs.getString("normalized_part_number"));
|
||||
foundMaterial.setHsCode(rs.getString("hs_code"));
|
||||
foundMaterial.setDeprecated(rs.getBoolean("is_deprecated"));
|
||||
Material data = new Material();
|
||||
|
||||
return foundMaterial;
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setName(rs.getString("name"));
|
||||
data.setPartNumber(rs.getString("part_number"));
|
||||
data.setNormalizedPartNumber(rs.getString("normalized_part_number"));
|
||||
data.setHsCode(rs.getString("hs_code"));
|
||||
data.setDeprecated(rs.getBoolean("is_deprecated"));
|
||||
|
||||
data.setPackaging(getMaterialPackaging(rs.getInt("id")).orElse(null));
|
||||
|
||||
|
||||
return data;
|
||||
}, id);
|
||||
|
||||
if(null == material) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// Query packaging data for the material
|
||||
String packagingQuery = """
|
||||
SELECT packaging.id,
|
||||
packaging_dimension.id AS hu_dimension_id, packaging_dimension.displayed_dimension_unit AS displayed_dimension_unit,
|
||||
packaging_dimension.displayed_weight_unit AS displayed_weight_unit, packaging_dimension.width AS width,
|
||||
packaging_dimension.length AS length, packaging_dimension.height AS height,
|
||||
packaging_dimension.content_unit_count AS content_unit_count, packaging_dimension.type AS type,
|
||||
node.id AS supplier_id, node.name AS supplier_name, node.address AS supplier_address,
|
||||
country.id AS country_id, country.name AS country_name, country.iso_code AS country_iso_code, country.region_code AS country_region_code
|
||||
return Optional.ofNullable(material);
|
||||
}
|
||||
|
||||
public Optional<MaterialPackaging> getMaterialPackaging(Integer id) {
|
||||
String query = """
|
||||
SELECT id
|
||||
FROM packaging
|
||||
LEFT JOIN packaging_dimension ON packaging.hu_dimension_id = packaging_dimension.id
|
||||
LEFT JOIN node ON packaging.supplier_node_id = node.id
|
||||
WHERE id = ?""";
|
||||
|
||||
|
||||
MaterialPackaging packaging = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
|
||||
MaterialPackaging data = new MaterialPackaging();
|
||||
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setHu(getPackagingDimensionById(rs.getInt("hu_dimension_id")).orElse(null) );
|
||||
data.setSupplier(getMaterialSupplier(rs.getInt("supplier_node_id")).orElse(null) );
|
||||
|
||||
return data;
|
||||
}, id);
|
||||
|
||||
return Optional.ofNullable(packaging);
|
||||
}
|
||||
|
||||
private Optional<PackagingDimension> getPackagingDimensionById(int id) {
|
||||
String query = """
|
||||
SELECT id, displayed_dimension_unit, displayed_weight_unit, width, length, height,
|
||||
content_unit_count, type, is_deprecated
|
||||
FROM packaging_dimension
|
||||
WHERE packaging_dimension.id = ? AND packaging_dimension.is_deprecated = ?""";
|
||||
|
||||
|
||||
var dimension = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
var data = new PackagingDimension();
|
||||
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setDimensionUnit(DimensionUnit.valueOf(rs.getString("displayed_dimension_unit")));
|
||||
data.setWeightUnit(WeightUnit.valueOf(rs.getString("displayed_weight_unit")));
|
||||
data.setType(PackagingType.valueOf(rs.getString("type")));
|
||||
data.setDeprecated(rs.getBoolean("is_deprecated"));
|
||||
|
||||
data.setWeight(data.getWeightUnit().convertFromG(rs.getInt("weight")));
|
||||
|
||||
data.setWidth(data.getDimensionUnit().convertFromMM(rs.getInt("width")));
|
||||
data.setHeight(data.getDimensionUnit().convertFromMM(rs.getInt("height")));
|
||||
data.setLength(data.getDimensionUnit().convertFromMM(rs.getInt("length")));
|
||||
|
||||
return data;
|
||||
}, id);
|
||||
|
||||
return Optional.ofNullable(dimension);
|
||||
}
|
||||
|
||||
private Optional<MaterialSupplier> getMaterialSupplier(Integer id) {
|
||||
String query = """
|
||||
SELECT node.id AS id, node.name AS name, node.address as address, node.is_source as is_source, node.is_sink as is_sink, node.is_intermediate as is_intermediate,
|
||||
country.id AS country_id, country.name AS country_name, country.iso_code AS country_iso_code, country.region_code AS country_region_code
|
||||
FROM node
|
||||
LEFT JOIN country ON node.country_id = country.id
|
||||
WHERE material_id = ? AND packaging.is_deprecated = FALSE
|
||||
""";
|
||||
WHERE node.id = ?""";
|
||||
|
||||
PackagingListEntry packaging = jdbcTemplate.queryForObject(packagingQuery, (packagingRs, packagingRowNum) -> {
|
||||
PackagingListEntry packagingEntry = new PackagingListEntry();
|
||||
var node = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
var data = new MaterialSupplier();
|
||||
|
||||
DimensionUnit dimensionUnit = DimensionUnit.valueOf(packagingRs.getString("displayed_dimension_unit"));
|
||||
WeightUnit weightUnit = WeightUnit.valueOf(packagingRs.getString("displayed_weight_unit"));
|
||||
var types = new ArrayList<NodeType>();
|
||||
|
||||
packagingEntry.setId(packagingRs.getInt("id"));
|
||||
packagingEntry.setParentId(packagingRs.getInt("parent_id"));
|
||||
packagingEntry.setWidth(dimensionUnit.convertFromMM(packagingRs.getInt("width")));
|
||||
packagingEntry.setHeight(dimensionUnit.convertFromMM(packagingRs.getInt("height")));
|
||||
packagingEntry.setLength(dimensionUnit.convertFromMM(packagingRs.getInt("length")));
|
||||
packagingEntry.setDimensionUnit(dimensionUnit);
|
||||
packagingEntry.setWeight(weightUnit.convertFromG(packagingRs.getInt("weight")));
|
||||
packagingEntry.setWeightUnit(weightUnit);
|
||||
packagingEntry.setContentUnitCount(packagingRs.getInt("content_unit_count"));
|
||||
packagingEntry.setType(packagingRs.getString("type"));
|
||||
if(rs.getBoolean("is_source")) { types.add(NodeType.SOURCE); };
|
||||
if(rs.getBoolean("is_sink")) { types.add(NodeType.SINK); };
|
||||
if(rs.getBoolean("is_intermediate")) { types.add(NodeType.INTERMEDIATE); };
|
||||
|
||||
if (packagingRs.getObject("supplier_id") != null) {
|
||||
NodeListEntry supplier = new NodeListEntry();
|
||||
supplier.setId(packagingRs.getInt("supplier_id"));
|
||||
supplier.setName(packagingRs.getString("supplier_name"));
|
||||
supplier.setAddress(packagingRs.getString("supplier_address"));
|
||||
var countryData = new CountryListEntry();
|
||||
countryData.setId(rs.getInt("country_id"));
|
||||
countryData.setName(rs.getString("country_name"));
|
||||
countryData.setIsoCode(rs.getString("country_iso_code"));
|
||||
countryData.setRegionCode(rs.getString("country_region_code"));
|
||||
|
||||
if (packagingRs.getObject("country_id") != null) {
|
||||
CountryListEntry country = new CountryListEntry();
|
||||
country.setId(packagingRs.getInt("country_id"));
|
||||
country.setName(packagingRs.getString("country_name"));
|
||||
country.setIsoCode(packagingRs.getString("country_iso_code"));
|
||||
country.setRegionCode(packagingRs.getString("country_region_code"));
|
||||
supplier.setCountry(country);
|
||||
}
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setName(rs.getString("name"));
|
||||
data.setAddress(rs.getString("address"));
|
||||
data.setCountry(countryData);
|
||||
data.setTypes(types);
|
||||
|
||||
packagingEntry.setSupplier(supplier);
|
||||
}
|
||||
return data;
|
||||
}, id);
|
||||
|
||||
return packagingEntry;
|
||||
}, material.getId());
|
||||
|
||||
material.setPackaging(packaging);
|
||||
|
||||
return Optional.of(material);
|
||||
return Optional.ofNullable(node);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
|
|||
|
|
@ -1,24 +1,15 @@
|
|||
package de.avatic.lcc.repositories;
|
||||
|
||||
import de.avatic.lcc.model.country.CountryListEntry;
|
||||
import de.avatic.lcc.model.materials.MaterialListEntry;
|
||||
import de.avatic.lcc.model.nodes.Location;
|
||||
import de.avatic.lcc.model.nodes.NodeListEntry;
|
||||
import de.avatic.lcc.model.nodes.NodeType;
|
||||
import de.avatic.lcc.model.packaging.*;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryPagination;
|
||||
import de.avatic.lcc.repositories.pagination.SearchQueryResult;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
|
|
@ -58,20 +49,20 @@ public class PackagingRepository {
|
|||
params.add(pagination.getLimit());
|
||||
params.add(pagination.getOffset());
|
||||
|
||||
var entries = jdbcTemplate.query(queryBuilder.toString(), (rs, rowNum) -> {
|
||||
var packaging = jdbcTemplate.query(queryBuilder.toString(), (rs, rowNum) -> {
|
||||
|
||||
PackagingListEntry data = new PackagingListEntry();
|
||||
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setHu(getPackagingDimensionById(rs.getInt("hu_dimension_id")).orElse(null) );
|
||||
data.setMaterial(getMaterialListEntryById(rs.getInt("material_id")).orElse(null) );
|
||||
data.setSupplier(getNodeListEntryById(rs.getInt("supplier_node_id")).orElse(null) );
|
||||
data.setSupplier(getPackagingSupplierById(rs.getInt("supplier_node_id")).orElse(null) );
|
||||
|
||||
|
||||
return data;
|
||||
}, params.toArray());
|
||||
|
||||
return new SearchQueryResult<>(entries, countPackaging(materialId, supplierId, excludeDeprecated), pagination.getLimit(), pagination.getOffset());
|
||||
return new SearchQueryResult<>(packaging, countPackaging(materialId, supplierId, excludeDeprecated), pagination.getLimit(), pagination.getOffset());
|
||||
}
|
||||
|
||||
private Integer countPackaging(Integer materialId, Integer supplierId, boolean excludeDeprecated) {
|
||||
|
|
@ -120,7 +111,7 @@ public class PackagingRepository {
|
|||
data.setShu(getPackagingDimensionById(rs.getInt("shu_dimension_id")).orElse(null) );
|
||||
|
||||
data.setMaterial(getMaterialListEntryById(rs.getInt("material_id")).orElse(null) );
|
||||
data.setSupplier(getNodeListEntryById(rs.getInt("supplier_node_id")).orElse(null) );
|
||||
data.setSupplier(getPackagingSupplierById(rs.getInt("supplier_node_id")).orElse(null) );
|
||||
|
||||
return data;
|
||||
}, id);
|
||||
|
|
@ -129,14 +120,14 @@ public class PackagingRepository {
|
|||
}
|
||||
|
||||
/* helper to get material preview move to material repo? */
|
||||
private Optional<MaterialListEntry> getMaterialListEntryById(Integer id) {
|
||||
private Optional<PackagingMaterial> getMaterialListEntryById(Integer id) {
|
||||
String query = """
|
||||
SELECT material.id AS id, material.name AS name, material.part_number, material.hs_code
|
||||
FROM material
|
||||
WHERE material.id = ?""";
|
||||
|
||||
var material = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
var data = new MaterialListEntry();
|
||||
var data = new PackagingMaterial();
|
||||
|
||||
data.setId(rs.getInt("id"));
|
||||
data.setName(rs.getString("name"));
|
||||
|
|
@ -149,7 +140,7 @@ public class PackagingRepository {
|
|||
return Optional.ofNullable(material);
|
||||
}
|
||||
|
||||
private Optional<NodeListEntry> getNodeListEntryById(Integer id) {
|
||||
private Optional<PackagingSupplier> getPackagingSupplierById(Integer id) {
|
||||
String query = """
|
||||
SELECT node.id AS id, node.name AS name, node.address as address, node.is_source as is_source, node.is_sink as is_sink, node.is_intermediate as is_intermediate,
|
||||
country.id AS country_id, country.name AS country_name, country.iso_code AS country_iso_code, country.region_code AS country_region_code
|
||||
|
|
@ -158,7 +149,7 @@ public class PackagingRepository {
|
|||
WHERE node.id = ?""";
|
||||
|
||||
var node = jdbcTemplate.queryForObject(query, (rs, rowNum) -> {
|
||||
var data = new NodeListEntry();
|
||||
var data = new PackagingSupplier();
|
||||
|
||||
var types = new ArrayList<NodeType>();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue