diff --git a/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java b/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java index 0b08c23..667339b 100644 --- a/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java +++ b/src/main/java/de/avatic/lcc/repositories/premise/PremiseRepository.java @@ -177,7 +177,7 @@ public class PremiseRepository { params.addValue("weight", hu.getWeight()); params.addValue("dimensionUnit", hu.getDimensionUnit().name()); params.addValue("weightUnit", hu.getWeightUnit().name()); - params.addValue("unitCount", hu.getContentUnitCount()*shu.getContentUnitCount()); + params.addValue("unitCount", hu.getContentUnitCount() * shu.getContentUnitCount()); params.addValue("stackable", isStackable); params.addValue("mixable", isMixable); params.addValue("premiseIds", premiseIds); @@ -276,7 +276,7 @@ public class PremiseRepository { String sql = sqlBuilder.toString(); var affectedRows = namedParameterJdbcTemplate.update(sql, params); - if(affectedRows != premiseIds.size()) + if (affectedRows != premiseIds.size()) throw new DatabaseException("Premise update failed for " + premiseIds.size() + " premises. Affected rows: " + affectedRows); } @@ -328,7 +328,7 @@ public class PremiseRepository { } ); - if(affectedRows != premiseIds.size()) + if (affectedRows != premiseIds.size()) throw new DatabaseException("Premise update failed for " + premiseIds.size() + " premises. Affected rows: " + affectedRows); } @@ -379,7 +379,7 @@ public class PremiseRepository { } ); - if(affectedRows != premiseIds.size()) + if (affectedRows != premiseIds.size()) throw new DatabaseException("Premise update failed for " + premiseIds.size() + " premises. Affected rows: " + affectedRows); } @@ -427,8 +427,8 @@ public class PremiseRepository { String placeholders = String.join(",", Collections.nCopies(premiseIds.size(), "?")); String query = """ - DELETE FROM premise - WHERE id IN (""" + placeholders + ") AND state = '" + PremiseState.DRAFT.name() + "'"; + DELETE FROM premise + WHERE id IN (""" + placeholders + ") AND state = '" + PremiseState.DRAFT.name() + "'"; jdbcTemplate.update(query, premiseIds.toArray()); @@ -461,7 +461,7 @@ public class PremiseRepository { var affectedRows = jdbcTemplate.update(sql, params); - if(affectedRows != premiseId.size()) + if (affectedRows != premiseId.size()) throw new DatabaseException("Premise update failed for " + premiseId.size() + " premises. Affected rows: " + affectedRows); } @@ -480,7 +480,7 @@ public class PremiseRepository { @Transactional public List findByMaterialIdAndSupplierId(Integer materialId, Integer supplierId, Integer userSupplierId, Integer userId) { - if((supplierId == null && userSupplierId == null) || (supplierId != null && userSupplierId != null)) + if ((supplierId == null && userSupplierId == null) || (supplierId != null && userSupplierId != null)) throw new DatabaseException("Either supplierId or userSupplierId must be null"); String query = """ @@ -488,14 +488,14 @@ public class PremiseRepository { WHERE material_id = ? AND (user_id = ? """; - if(userSupplierId != null) + if (userSupplierId != null) query += ") AND user_supplier_node_id = ?"; else query += "OR state = 'COMPLETED') AND supplier_node_id = ?"; query += " ORDER BY updated_at DESC"; - return jdbcTemplate.query(query, new PremiseMapper(), materialId, userId, userSupplierId != null ? userSupplierId : supplierId); + return jdbcTemplate.query(query, new PremiseMapper(), materialId, userId, userSupplierId != null ? userSupplierId : supplierId); } @Transactional @@ -615,13 +615,16 @@ public class PremiseRepository { ); } + @Transactional public void setPackagingId(Integer id, Integer packagingId) { String query = "UPDATE premise SET packaging_id = ? WHERE id = ?"; var affectedRows = jdbcTemplate.update(query, packagingId, id); - if(affectedRows == 0) + + if (affectedRows == 0) throw new DatabaseException("No premise found with id " + id); + } @Transactional @@ -632,7 +635,7 @@ public class PremiseRepository { var otherIds = jdbcTemplate.queryForList(query, Integer.class, premiseIds, userId); - if(!otherIds.isEmpty()) { + if (!otherIds.isEmpty()) { throw new ForbiddenException("Access violation. Cannot open premise with ids = " + otherIds); } } @@ -845,29 +848,29 @@ public class PremiseRepository { entity.setId(rs.getInt("id")); entity.setPackagingId(rs.getInt("packaging_id")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setPackagingId(null); entity.setMaterialId(rs.getInt("material_id")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setMaterialId(null); entity.setSupplierNodeId(rs.getInt("supplier_node_id")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setSupplierNodeId(null); entity.setUserSupplierNodeId(rs.getInt("user_supplier_node_id")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setUserSupplierNodeId(null); entity.setLocation(new Location(rs.getBigDecimal("geo_lng").doubleValue(), rs.getBigDecimal("geo_lat").doubleValue())); entity.setCountryId(rs.getInt("country_id")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setCountryId(null); entity.setUserId(rs.getInt("user_id")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setUserId(null); entity.setMaterialCost(rs.getBigDecimal("material_cost")); @@ -877,40 +880,40 @@ public class PremiseRepository { entity.setTariffRate(rs.getBigDecimal("tariff_rate")); entity.setFcaEnabled(rs.getBoolean("is_fca_enabled")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setFcaEnabled(null); entity.setOverseaShare(rs.getBigDecimal("oversea_share")); entity.setIndividualHuHeight(rs.getInt("individual_hu_height")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setIndividualHuHeight(null); entity.setIndividualHuWidth(rs.getInt("individual_hu_width")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setIndividualHuWidth(null); entity.setIndividualHuLength(rs.getInt("individual_hu_length")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setIndividualHuLength(null); entity.setIndividualHuWeight(rs.getInt("individual_hu_weight")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setIndividualHuWeight(null); entity.setHuDisplayedDimensionUnit(DimensionUnit.valueOf(rs.getString("hu_displayed_dimension_unit"))); entity.setHuDisplayedWeightUnit(WeightUnit.valueOf(rs.getString("hu_displayed_weight_unit"))); entity.setHuStackable(rs.getBoolean("hu_stackable")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setHuStackable(null); entity.setHuMixable(rs.getBoolean("hu_mixable")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setHuMixable(null); entity.setHuUnitCount(rs.getInt("hu_unit_count")); - if(rs.wasNull()) + if (rs.wasNull()) entity.setHuUnitCount(null); entity.setState(PremiseState.valueOf(rs.getString("state"))); diff --git a/src/main/java/de/avatic/lcc/service/calculation/PremiseCreationService.java b/src/main/java/de/avatic/lcc/service/calculation/PremiseCreationService.java index 1a162d6..21d3b14 100644 --- a/src/main/java/de/avatic/lcc/service/calculation/PremiseCreationService.java +++ b/src/main/java/de/avatic/lcc/service/calculation/PremiseCreationService.java @@ -100,7 +100,7 @@ public class PremiseCreationService { premiseRepository.updateMaterial(Collections.singletonList(p.getId()), old.getHsCode(), old.getTariffRate()); premiseRepository.updatePrice(Collections.singletonList(p.getId()), old.getMaterialCost(), old.getFcaEnabled(), old.getOverseaShare()); premiseRepository.updatePackaging(Collections.singletonList(p.getId()), dimensionTransformer.toDimensionEntity(old), old.getHuStackable(), old.getHuMixable()); - premiseRepository.setPackagingId(p.getId(), old.getId()); + premiseRepository.setPackagingId(p.getId(), old.getPackagingId()); } private void fillPremise(TemporaryPremise p, Integer userId) {