]> git.mxchange.org Git - jproduct-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 18 Nov 2017 14:27:10 +0000 (15:27 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 18 Nov 2017 16:35:46 +0000 (17:35 +0100)
- added product size, like for shoes or clothing
- made combination of i18n key, age group and size unique
- added AgeGroup enumeration to product entity

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jproduct/model/product/GenericProduct.java
src/org/mxchange/jproduct/model/product/Product.java
src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java [new file with mode: 0644]

index 508360a5b496fe4a712cc3fc1346dc115d73599a..bdbcc0e61fb2dcc26445df9b70404f7cc5da24f1 100644 (file)
@@ -23,9 +23,12 @@ import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.Index;
 import javax.persistence.JoinColumn;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
@@ -38,6 +41,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jproduct.model.category.Category;
 import org.mxchange.jproduct.model.category.ProductCategory;
+import org.mxchange.jproduct.model.product.agegroup.AgeGroup;
 
 /**
  * Generic product class
@@ -46,7 +50,16 @@ import org.mxchange.jproduct.model.category.ProductCategory;
  * TODO: Find a better name
  */
 @Entity (name = "generic_products")
-@Table (name = "generic_products")
+@Table (
+               name = "generic_products",
+               indexes = {
+                       @Index (
+                                       name = "idx_i18n_age_size",
+                                       columnList = "product_i18n_key,product_age_group,product_size",
+                                       unique = true
+                       )
+               }
+)
 @NamedQueries (
                {
                        @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"),
@@ -62,6 +75,13 @@ public class GenericProduct implements Product {
        @Transient
        private static final long serialVersionUID = 54_578_571_769_283L;
 
+       /**
+        * Product's age group (if any)
+        */
+       @Column (name = "product_age_group")
+       @Enumerated (EnumType.STRING)
+       private AgeGroup productAgeGroup;
+
        /**
         * Availability of product
         */
@@ -102,7 +122,7 @@ public class GenericProduct implements Product {
         * I18n key of product
         */
        @Basic (optional = false)
-       @Column (name = "product_i18n_key", length = 100, nullable = false, unique = true)
+       @Column (name = "product_i18n_key", length = 100, nullable = false)
        private String productI18nKey;
 
        /**
@@ -132,6 +152,12 @@ public class GenericProduct implements Product {
        @Column (name = "product_number")
        private Long productNumber;
 
+       /**
+        * Product size (like for shoes, clothing)
+        */
+       @Column (name = "product_size", length = 10)
+       private String productSize;
+
        /**
         * Tax rate (0-1, by 1=100%)
         */
@@ -248,11 +274,25 @@ public class GenericProduct implements Product {
                        return false;
                } else if (!Objects.equals(this.getProductI18nKey(), product.getProductI18nKey())) {
                        return false;
+               } else if (!Objects.equals(this.getProductAgeGroup(), product.getProductAgeGroup())) {
+                       return false;
+               } else if (!Objects.equals(this.getProductSize(), product.getProductSize())) {
+                       return false;
                }
 
                return true;
        }
 
+       @Override
+       public AgeGroup getProductAgeGroup () {
+               return this.productAgeGroup;
+       }
+
+       @Override
+       public void setProductAgeGroup (final AgeGroup productAgeGroup) {
+               this.productAgeGroup = productAgeGroup;
+       }
+
        @Override
        public Boolean getProductAvailability () {
                return this.productAvailability;
@@ -355,6 +395,16 @@ public class GenericProduct implements Product {
                this.productNumber = productNumber;
        }
 
+       @Override
+       public String getProductSize () {
+               return this.productSize;
+       }
+
+       @Override
+       public void setProductSize (final String productSize) {
+               this.productSize = productSize;
+       }
+
        @Override
        public Float getProductTaxRate () {
                return this.productTaxRate;
@@ -391,6 +441,8 @@ public class GenericProduct implements Product {
 
                hash = 23 * hash + Objects.hashCode(this.getProductId());
                hash = 23 * hash + Objects.hashCode(this.getProductI18nKey());
+               hash = 23 * hash + Objects.hashCode(this.getProductAgeGroup());
+               hash = 23 * hash + Objects.hashCode(this.getProductSize());
 
                return hash;
        }
index dce0e96d961c19a27a17faea7c7fdf471a59c322..474b5d33e7a4559d8ebd52764505aa768020a958 100644 (file)
@@ -20,6 +20,7 @@ import java.io.Serializable;
 import java.util.Date;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jproduct.model.category.Category;
+import org.mxchange.jproduct.model.product.agegroup.AgeGroup;
 
 /**
  * An interface for in database storable products
@@ -210,6 +211,34 @@ public interface Product extends Serializable {
         */
        void setProductNumber (final Long productNumber);
 
+       /**
+        * Getter for product's size
+        * <p>
+        * @return Product's size
+        */
+       String getProductSize ();
+
+       /**
+        * Setter for product's size
+        * <p>
+        * @param productSize Product's size
+        */
+       void setProductSize (final String productSize);
+
+       /**
+        * Getter for product's age group
+        * <p>
+        * @return Product's age group
+        */
+       AgeGroup getProductAgeGroup ();
+
+       /**
+        * Setter for product's age group
+        * <p>
+        * @param productAgeGroup Product's age group
+        */
+       void setProductAgeGroup (final AgeGroup productAgeGroup);
+
        @Override
        boolean equals (final Object object);
 
diff --git a/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java b/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java
new file mode 100644 (file)
index 0000000..673e945
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 Roland Haeder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.product.agegroup;
+
+/**
+ * An enumeration for age classes
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public enum AgeGroup {
+
+       /**
+        * Age group "new born"
+        */
+       AGE_GROUP_NEWBORN("AGE_GROUP_NEWBORN"), //NOI18N
+       /**
+        * Age group "baby"
+        */
+       AGE_GROUP_BABY("AGE_GROUP_BABY"), //NOI18N
+       /**
+        * Age group "child"
+        */
+       AGE_GROUP_CHILD("AGE_GROUP_CHILD"), //NOI18N
+       /**
+        * Age group "youth"
+        */
+       AGE_GROUP_YOUTH("AGE_GROUP_YOUTH"), //NOI18N
+       /**
+        * Age group "adult"
+        */
+       AGE_GROUP_ADULT("AGE_GROUP_ADULT"), //NOI18N
+       /**
+        * Age group "senior"
+        */
+       AGE_GROUP_SENIOR("AGE_GROUP_SENIOR"); //NOI18N//NOI18N
+
+       /**
+        * I18n key for age group/class
+        */
+       private final String i18nKey;
+
+       /**
+        * Constructor with all enumeration fields
+        * <p>
+        * @param i18nKey I18n key for age class
+        */
+       private AgeGroup (final String i18nKey) {
+               // Set all values
+               this.i18nKey = i18nKey;
+       }
+
+       /**
+        * Getter for age group's i18n key
+        * <p>
+        * @return Age group's i18n key
+        */
+       public String getI18nKey () {
+               return this.i18nKey;
+       }
+
+}