From ad937d00f5eb8fb04ad1d2d29736551b2f7d0dc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 31 Oct 2017 19:22:30 +0100 Subject: [PATCH] Continued a bit: - removed single quotes around {0}, it seems to confuse the parser? - renamed productTitle -> productI18nKey (like PRODUCT_MILK for milk) to allow internationalization/localization of products MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../events/category/CategoryAddedEvent.java | 5 +- .../events/product/ProductAddedEvent.java | 4 +- .../CategoryAlreadyAddedException.java | 2 +- .../category/CategoryNotFoundException.java | 4 +- .../product/ProductAlreadyAddedException.java | 2 +- .../model/product/GenericProduct.java | 52 +++++++++---------- .../jproduct/model/product/Product.java | 12 ++--- 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/org/mxchange/jproduct/events/category/CategoryAddedEvent.java b/src/org/mxchange/jproduct/events/category/CategoryAddedEvent.java index 580ec09..4237bf1 100644 --- a/src/org/mxchange/jproduct/events/category/CategoryAddedEvent.java +++ b/src/org/mxchange/jproduct/events/category/CategoryAddedEvent.java @@ -46,9 +46,12 @@ public class CategoryAddedEvent implements AddedCategoryEvent { if (null == addedCategory) { // Is NULL, throw NPE throw new NullPointerException("addedCategory is null"); //NOI18N + } else if (addedCategory.getCategoryI18nKey() == null) { + // Is NULL, throw NPE again + throw new NullPointerException("addedCategory.categoryI18nKey is null"); //NOI18N } else if (addedCategory.getCategoryI18nKey().isEmpty()) { // Empty title - throw new IllegalArgumentException("addedCategory.categoryTitle is empty"); //NOI18N + throw new IllegalArgumentException("addedCategory.categoryI18nKey is empty"); //NOI18N } else if (addedCategory.getCategoryId() == null) { // Id is NULL throw new NullPointerException("addedCategory.categoryId is null"); //NOI18N diff --git a/src/org/mxchange/jproduct/events/product/ProductAddedEvent.java b/src/org/mxchange/jproduct/events/product/ProductAddedEvent.java index 9c2df8b..43f16fd 100644 --- a/src/org/mxchange/jproduct/events/product/ProductAddedEvent.java +++ b/src/org/mxchange/jproduct/events/product/ProductAddedEvent.java @@ -46,9 +46,9 @@ public class ProductAddedEvent implements AddedProductEvent { if (null == addedProduct) { // Is NULL, throw NPE throw new NullPointerException("addedProduct is null"); //NOI18N - } else if (addedProduct.getProductTitle().isEmpty()) { + } else if (addedProduct.getProductI18nKey().isEmpty()) { // Empty title - throw new IllegalArgumentException("addedProduct.categoryTitle is empty"); //NOI18N + throw new IllegalArgumentException("addedProduct.productI18nKey is empty"); //NOI18N } else if (addedProduct.getProductId() == null) { // Id is NULL throw new NullPointerException("addedProduct.productId is null"); //NOI18N diff --git a/src/org/mxchange/jproduct/exceptions/category/CategoryAlreadyAddedException.java b/src/org/mxchange/jproduct/exceptions/category/CategoryAlreadyAddedException.java index 6e6b342..ce6d9c1 100644 --- a/src/org/mxchange/jproduct/exceptions/category/CategoryAlreadyAddedException.java +++ b/src/org/mxchange/jproduct/exceptions/category/CategoryAlreadyAddedException.java @@ -48,6 +48,6 @@ public class CategoryAlreadyAddedException extends Exception { */ public CategoryAlreadyAddedException (final Category category) { // Call super constructor - super(MessageFormat.format("Category with i18n key '{0}' already added.", category.getCategoryI18nKey())); //NOI18N + super(MessageFormat.format("Category with i18n key {0} already added.", category.getCategoryI18nKey())); //NOI18N } } diff --git a/src/org/mxchange/jproduct/exceptions/category/CategoryNotFoundException.java b/src/org/mxchange/jproduct/exceptions/category/CategoryNotFoundException.java index d3fc25f..52f5dec 100644 --- a/src/org/mxchange/jproduct/exceptions/category/CategoryNotFoundException.java +++ b/src/org/mxchange/jproduct/exceptions/category/CategoryNotFoundException.java @@ -48,7 +48,7 @@ public class CategoryNotFoundException extends Exception { */ public CategoryNotFoundException (final Category category) { // Call super constructor - super(MessageFormat.format("Category with i18n key '{0}' already added.", category.getCategoryI18nKey())); //NOI18N + super(MessageFormat.format("Category with i18n key {0} already added.", category.getCategoryI18nKey())); //NOI18N } /** @@ -58,7 +58,7 @@ public class CategoryNotFoundException extends Exception { */ public CategoryNotFoundException (final Long categoryId) { // Call super constructor - super(MessageFormat.format("Category with id '{0}' not found.", categoryId)); //NOI18N + super(MessageFormat.format("Category with id {0} not found.", categoryId)); //NOI18N } } diff --git a/src/org/mxchange/jproduct/exceptions/product/ProductAlreadyAddedException.java b/src/org/mxchange/jproduct/exceptions/product/ProductAlreadyAddedException.java index 32accde..c86f6ff 100644 --- a/src/org/mxchange/jproduct/exceptions/product/ProductAlreadyAddedException.java +++ b/src/org/mxchange/jproduct/exceptions/product/ProductAlreadyAddedException.java @@ -48,7 +48,7 @@ public class ProductAlreadyAddedException extends Exception { */ public ProductAlreadyAddedException (final Product product) { // Call super constructor - super(MessageFormat.format("Product with title '{0}' already added.", product.getProductTitle())); //NOI18N + super(MessageFormat.format("Product with title {0} already added.", product.getProductI18nKey())); //NOI18N } } diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index 424d8b9..8480c63 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -86,8 +86,8 @@ public class GenericProduct implements Product { /** * Currency code for both prices, like EUR or USD */ - @Basic(optional = false) - @Column(name = "product_currency_code", nullable = false, length = 3) + @Basic (optional = false) + @Column (name = "product_currency_code", nullable = false, length = 3) private String productCurrencyCode; /** @@ -97,6 +97,13 @@ public class GenericProduct implements Product { @Column (name = "product_gross_price", nullable = false) private Float productGrossPrice; + /** + * I18n key of product + */ + @Basic (optional = false) + @Column (name = "product_i18n_key", length = 100, nullable = false, unique = true) + private String productI18nKey; + /** * Id number of product */ @@ -108,8 +115,8 @@ public class GenericProduct implements Product { /** * The company that has manufactured/produced this product */ - @JoinColumn(name = "product_manufacturer_id", referencedColumnName = "company_data_id") - @OneToOne(targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH) + @JoinColumn (name = "product_manufacturer_id", referencedColumnName = "company_data_id") + @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH) private BasicData productManfacturer; /** @@ -124,13 +131,6 @@ public class GenericProduct implements Product { @Column (name = "product_tax_rate") private Float productTaxRate; - /** - * Title of product - */ - @Basic (optional = false) - @Column (name = "product_title", length = 100, nullable = false, unique = true) - private String productTitle; - /** * Amount of this product (for example 1 for 1 liter) */ @@ -152,15 +152,15 @@ public class GenericProduct implements Product { /** * Constructor will all required data *

- * @param productTitle Name of product + * @param productI18nKey I18n key of product * @param productGrossPrice Product's gross price * @param productCurrencyCode code for both prices * @param productCategory Category instance * @param productAvailability Availability (selectable by customer) */ - public GenericProduct (final String productTitle, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability) { + public GenericProduct (final String productI18nKey, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability) { // Set all here - this.productTitle = productTitle; + this.productI18nKey = productI18nKey; this.productGrossPrice = productGrossPrice; this.productCurrencyCode = productCurrencyCode; this.productCategory = productCategory; @@ -181,7 +181,7 @@ public class GenericProduct implements Product { if (!Objects.equals(this.getProductId(), product.getProductId())) { return false; - } else if (!Objects.equals(this.getProductTitle(), product.getProductTitle())) { + } else if (!Objects.equals(this.getProductI18nKey(), product.getProductI18nKey())) { return false; } @@ -240,6 +240,16 @@ public class GenericProduct implements Product { this.productGrossPrice = productGrossPrice; } + @Override + public String getProductI18nKey () { + return this.productI18nKey; + } + + @Override + public void setProductI18nKey (final String productI18nKey) { + this.productI18nKey = productI18nKey; + } + @Override public Long getProductId () { return this.productId; @@ -280,16 +290,6 @@ public class GenericProduct implements Product { this.productTaxRate = productTaxRate; } - @Override - public String getProductTitle () { - return this.productTitle; - } - - @Override - public void setProductTitle (final String productTitle) { - this.productTitle = productTitle; - } - @Override public Float getProductUnitAmount () { return this.productUnitAmount; @@ -315,7 +315,7 @@ public class GenericProduct implements Product { int hash = 7; hash = 23 * hash + Objects.hashCode(this.getProductId()); - hash = 23 * hash + Objects.hashCode(this.getProductTitle()); + hash = 23 * hash + Objects.hashCode(this.getProductI18nKey()); return hash; } diff --git a/src/org/mxchange/jproduct/model/product/Product.java b/src/org/mxchange/jproduct/model/product/Product.java index 0dfcf7a..31ef188 100644 --- a/src/org/mxchange/jproduct/model/product/Product.java +++ b/src/org/mxchange/jproduct/model/product/Product.java @@ -155,18 +155,18 @@ public interface Product extends Serializable { void setProductCurrencyCode (final String productCurrencyCode); /** - * Getter for title. + * Getter for i18n key of product *

- * @return Title of product + * @return I18n key of product */ - String getProductTitle (); + String getProductI18nKey (); /** - * Title of product + * Setter for i18n key of product *

- * @param productTitle the title to set + * @param productI18nKey I18n key */ - void setProductTitle (final String productTitle); + void setProductI18nKey (final String productI18nKey); /** * Getter for product's unit amount -- 2.39.5