From 083fea9cdf1d00c7400b6c6249d06e4f70691052 Mon Sep 17 00:00:00 2001 From: Lizi Boros Date: Tue, 14 May 2019 13:39:49 +0200 Subject: [PATCH 01/76] Second user story implemented: all products listed on index under default category --- src/main/java/com/codecool/shop/config/Initializer.java | 3 +++ .../java/com/codecool/shop/controller/ProductController.java | 4 ++-- src/main/webapp/templates/product/index.html | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index 68bc9ff..d9aad63 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -31,11 +31,14 @@ public void contextInitialized(ServletContextEvent sce) { //setting up a new product category ProductCategory tablet = new ProductCategory("Tablet", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); + ProductCategory tablet2 = new ProductCategory("Tablet2", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); productCategoryDataStore.add(tablet); + productCategoryDataStore.add(tablet2); //setting up products and printing it productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); + productDataStore.add(new Product("random", 8345349, "USD", "lalalla.", tablet2, amazon)); } } diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 53c7df0..c9f32c8 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -31,8 +31,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); - context.setVariable("category", productCategoryDataStore.find(1)); - context.setVariable("products", productDataStore.getBy(productCategoryDataStore.find(1))); +// context.setVariable("category", productCategoryDataStore.find(1)); + context.setVariable("products", productDataStore.getAll()); engine.process("product/index.html", context, resp.getWriter()); } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index f9fc8b1..d1a7a94 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -36,7 +36,7 @@

Codecool Shop

- Category Title + Products
From 8d516538ebd3c7450b50a3b8fa38f4af0ad31e58 Mon Sep 17 00:00:00 2001 From: Lizi Boros Date: Tue, 14 May 2019 14:08:39 +0200 Subject: [PATCH 02/76] Product filtering front-end done --- .../shop/controller/ProductController.java | 6 ++++- src/main/webapp/templates/product/index.html | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index c9f32c8..e829bdc 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -2,9 +2,11 @@ import com.codecool.shop.dao.ProductCategoryDao; import com.codecool.shop.dao.ProductDao; +import com.codecool.shop.dao.SupplierDao; import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; import com.codecool.shop.dao.implementation.ProductDaoMem; import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.dao.implementation.SupplierDaoMem; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -24,6 +26,7 @@ public class ProductController extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ProductDao productDataStore = ProductDaoMem.getInstance(); ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); + SupplierDao supplierDao = SupplierDaoMem.getInstance(); // Map params = new HashMap<>(); // params.put("category", productCategoryDataStore.find(1)); @@ -31,8 +34,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); -// context.setVariable("category", productCategoryDataStore.find(1)); + context.setVariable("suppliers", supplierDao.getAll()); context.setVariable("products", productDataStore.getAll()); + context.setVariable("categories", productCategoryDataStore.getAll()); engine.process("product/index.html", context, resp.getWriter()); } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index d1a7a94..1658d19 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -39,6 +39,28 @@

Codecool Shop

Products
+
+ + +
+ +
+ + +
+
From 6fc23da67f238f2c483ebf5ed4ad5324626a2d0a Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Tue, 14 May 2019 14:41:23 +0200 Subject: [PATCH 03/76] Order class --- .../java/com/codecool/shop/model/Order.java | 45 +++++++++++++++++++ .../java/com/codecool/shop/model/Product.java | 3 ++ 2 files changed, 48 insertions(+) create mode 100644 src/main/java/com/codecool/shop/model/Order.java diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java new file mode 100644 index 0000000..55e323f --- /dev/null +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -0,0 +1,45 @@ +package com.codecool.shop.model; + +import java.util.HashMap; +import java.util.Map; + + +public class Order { + + private static int instanceCounter; + private int id; + private float sumOfPrice; + HashMap products; + + public Order(){ + this.id = instanceCounter++; + products = new HashMap<>(); + } + + public float getSumOfPrice(){ + for (Map.Entry product : products.entrySet()){ + sumOfPrice += product.getKey().getDefaultPrice() * product.getValue(); + } + return sumOfPrice; + } + public void add(Product product){ + if(products.get(product) != null){ + products.put(product, products.get(product) + 1); + }else{ + products.put(product, 1); + } + } + + public void reduce(Product product){ + if(products.get(product) == 1){ + products.remove(product); + }else{ + products.put(product, products.get(product) - 1); + } + } + + public HashMap getProductsOfOrder(){ + return products; + } + +} diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java index eaf07a6..727cc90 100644 --- a/src/main/java/com/codecool/shop/model/Product.java +++ b/src/main/java/com/codecool/shop/model/Product.java @@ -59,6 +59,9 @@ public void setSupplier(Supplier supplier) { this.supplier = supplier; this.supplier.addProduct(this); } + public String getName(){ + return name; + } @Override public String toString() { From 46728f0784e189d6c4d42e81ce6f822144843a82 Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Tue, 14 May 2019 14:47:52 +0200 Subject: [PATCH 04/76] Order class --- src/main/java/com/codecool/shop/model/Product.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java index 727cc90..cda35df 100644 --- a/src/main/java/com/codecool/shop/model/Product.java +++ b/src/main/java/com/codecool/shop/model/Product.java @@ -59,9 +59,7 @@ public void setSupplier(Supplier supplier) { this.supplier = supplier; this.supplier.addProduct(this); } - public String getName(){ - return name; - } + @Override public String toString() { From 54ae9c6dda67b1b0e544eb8d7ba14f3363932c68 Mon Sep 17 00:00:00 2001 From: Lizi Boros Date: Tue, 14 May 2019 14:57:57 +0200 Subject: [PATCH 05/76] Front-end small changes --- .../shop/controller/ProductController.java | 5 ++ src/main/webapp/templates/product/index.html | 46 +++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index e829bdc..4f5214a 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -40,4 +40,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se engine.process("product/index.html", context, resp.getWriter()); } + + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } + } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 1658d19..90810ce 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -39,30 +39,36 @@

Codecool Shop

Products
-
- - -
+ + + + + + + + -
- - + +
-
+
From 6328c539d27a4fe98fa4762d1da124363f1e7ab1 Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Tue, 14 May 2019 15:00:24 +0200 Subject: [PATCH 06/76] get sum of products --- src/main/java/com/codecool/shop/model/Order.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 55e323f..014046f 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -9,6 +9,7 @@ public class Order { private static int instanceCounter; private int id; private float sumOfPrice; + private int sumOfProducts; HashMap products; public Order(){ @@ -17,6 +18,7 @@ public Order(){ } public float getSumOfPrice(){ + sumOfPrice = 0; for (Map.Entry product : products.entrySet()){ sumOfPrice += product.getKey().getDefaultPrice() * product.getValue(); } @@ -38,6 +40,14 @@ public void reduce(Product product){ } } + public int getNumberOfProducts(){ + sumOfProducts = 0; + for(int value : products.values()){ + sumOfProducts += value; + } + return sumOfProducts; + } + public HashMap getProductsOfOrder(){ return products; } From 590b7673da31d975eb3ea4602a2daa35d5d7bb6c Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 14 May 2019 15:14:11 +0200 Subject: [PATCH 07/76] initialize an Order Object --- src/main/java/com/codecool/shop/config/Initializer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index 68bc9ff..da37d30 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -6,6 +6,7 @@ import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; import com.codecool.shop.dao.implementation.ProductDaoMem; import com.codecool.shop.dao.implementation.SupplierDaoMem; +import com.codecool.shop.model.Order; import com.codecool.shop.model.Product; import com.codecool.shop.model.ProductCategory; import com.codecool.shop.model.Supplier; @@ -37,5 +38,8 @@ public void contextInitialized(ServletContextEvent sce) { productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); + + //setting up new order + Order order = new Order(); } } From e55e3f13c8b1136c20b3ec7603b2c503ec793de7 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 14 May 2019 15:34:15 +0200 Subject: [PATCH 08/76] corrected reduce method in Order Class --- src/main/java/com/codecool/shop/model/Order.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 014046f..78cd146 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -33,10 +33,12 @@ public void add(Product product){ } public void reduce(Product product){ - if(products.get(product) == 1){ - products.remove(product); - }else{ - products.put(product, products.get(product) - 1); + if (products.get(product) != null) { + if(products.get(product) == 1){ + products.remove(product); + }else{ + products.put(product, products.get(product) - 1); + } } } From 1909660b90ab558d56e5064ca71f08c680ca7407 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 14 May 2019 15:35:11 +0200 Subject: [PATCH 09/76] getSumOfPrice method in Order Class --- src/main/java/com/codecool/shop/model/Order.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 78cd146..76ba870 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -54,4 +54,7 @@ public HashMap getProductsOfOrder(){ return products; } + public float getSumOfPriceBy(Product product) { + return products.get(product) * product.getDefaultPrice(); + } } From 5a4a1902dba0768174a0b3b9332bb59f2d0e7de1 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 14 May 2019 15:35:29 +0200 Subject: [PATCH 10/76] test cases for Order Class --- .../java/com/codecool/shop/config/Initializer.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index da37d30..5fff5b7 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -41,5 +41,17 @@ public void contextInitialized(ServletContextEvent sce) { //setting up new order Order order = new Order(); + + //testing the order methods + Product product_eins = new Product("Something", 20f, "USD", "nope", tablet, amazon); + Product product_zwei = new Product("Something else", 25f, "USD", "nope and nope", tablet, lenovo); + + order.add(product_eins); + order.add(product_eins); + order.add(product_zwei); + order.reduce(product_eins); + order.reduce(product_eins); + order.reduce(product_eins); + } } From b64f6401ae1efdedd69a04e578bd55fb7bdd1c1b Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 14 May 2019 15:37:16 +0200 Subject: [PATCH 11/76] refactoring in Product --- src/main/java/com/codecool/shop/model/Product.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java index cda35df..e388f93 100644 --- a/src/main/java/com/codecool/shop/model/Product.java +++ b/src/main/java/com/codecool/shop/model/Product.java @@ -76,4 +76,4 @@ public String toString() { this.productCategory.getName(), this.supplier.getName()); } -} +} \ No newline at end of file From b3d387cc99b89506120b6ba9b1c24ca0b7e19f40 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Tue, 14 May 2019 16:22:50 +0200 Subject: [PATCH 12/76] database ready, initialisations are modified accordingly --- pom.xml | 4 +- src/data/animals.csv | 48 +++++++++++++++++++ src/data/categories.csv | 4 ++ src/data/suppliers.csv | 12 +++++ .../com/codecool/shop/config/Initializer.java | 18 +++---- .../codecool/shop/dao/ProductCategoryDao.java | 2 + .../implementation/ProductCategoryDaoMem.java | 21 ++++++++ .../dao/implementation/ProductDaoMem.java | 12 +++++ .../dao/implementation/SupplierDaoMem.java | 24 ++++++++++ .../java/com/codecool/shop/model/Product.java | 32 +++++++++---- .../codecool/shop/model/ProductCategory.java | 5 ++ .../com/codecool/shop/model/Supplier.java | 15 +++++- 12 files changed, 176 insertions(+), 21 deletions(-) create mode 100644 src/data/animals.csv create mode 100644 src/data/categories.csv create mode 100644 src/data/suppliers.csv diff --git a/pom.xml b/pom.xml index 415c26c..83a7a52 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ maven-compiler-plugin 3.7.0 - 1.8 - 1.8 + 11 + 11 diff --git a/src/data/animals.csv b/src/data/animals.csv new file mode 100644 index 0000000..020fd0d --- /dev/null +++ b/src/data/animals.csv @@ -0,0 +1,48 @@ +Griffon Vulture|Bird|1990|USD|The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.|https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933 +Bald Eagle|Bird|3490|USD|The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aiētos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.|https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710 +Osprey|Bird|1249|USD|The osprey (Pandion haliaetus) — also called fish eagle, sea hawk, river hawk, and fish hawk — is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.|https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703 +Southern Cassowary|Bird|8990|USD|The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.|https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613 +Wilson's Bird-of-paradise|Bird|5499|USD|The Wilson's bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson's bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson's bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).|https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933 +Henderson Fruit Dove|Bird|12990|USD|The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.|https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012 +Seram Swiftlet|Bird|799|USD|The Seram swiftlet (Aerodramus ceramensis), is a species of swift in the Apodidae family. It is endemic to Buru and Seram Islands. It used to be considered a subspecies of the Moluccan swiftlet. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical moist montane forests.|https://vignette.wikia.nocookie.net/animals/images/d/d3/Moluccanswift2.jpg/revision/latest?cb=20160826191222 +Yap Monarch|Bird|499|USD|The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.|https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519 +Harpy Eagle|Bird|999|USD|It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.|https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709 +Speckled Piculet|Bird|1390|USD|The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.|https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813 +Congo Serpent Eagle|Bird|2990|USD|The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests’ dark understories.|https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745 +Bearded Bellbird|Bird|6990|USD|This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).|https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300 +Western Gorilla|Mammal|7290|USD|The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.|https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304 +Snow Leopard|Mammal|15490|USD|The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.|https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225 +Humpback Whale|Mammal|39990|USD|The Humpback Whale is a species from the Megaptera genus.Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.|https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349 +Gray Wolf|Mammal|14990|USD|The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They're also highly territorial.|https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608 +Moose|Mammal|27990|USD|The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males; other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.|https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550 +Carnivora|Mammal|99990|USD|The Carnivora is an order from the Mammalia class. This group includes cats, dogs, bears, wolves, seals, walruses, otters and weasels. Carnivorans are primarily terrestrial and usually have strong sharp claws, with never fewer than four toes on each foot, and well-developed, prominent canine teeth, cheek teeth that generally have cutting edges. The last premolar of the upper jaw and first molar of the lower are termed the carnassials or sectorial teeth. These are blade-like teeth that occlude with a scissor-like action for shearing and shredding meat. Carnassials are most highly developed in the Felidae and the least developed in the Ursidae.The first carnivoran was a carnivore, and nearly all carnivorans today primarily eat meat.|https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821 +Tiger|Mammal|49990|USD|The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.|https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111 +Lion|Mammal|32790|USD|The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.|https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314 +Leopard|Mammal|26790|USD|The leopard (Panthera pardus) (English pronunciation: /ˈlɛpərd/) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard's rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar's do. Both leopards and jaguars that are melanistic are known as black panthers.|https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105 +Aardvark|Mammal|799|USD|The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or 'thumb'), resulting in four toes, while the rear feet have all five toes.|https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128 +Bison|Mammal|37490|USD|The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American; Bison antiquus, B. latifrons, and B. occidentalis. The fourth; the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species; the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)|https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550 +Cheetah|Mammal|24990|USD|The cheetah (pronounced /ˈchē-tə/) (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.|https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800 +Inland Taipan|Reptile|1290|USD|The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.|https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446 +Green Sea Turtle|Reptile|499|USD|The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.|https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939 +Komodo Dragon|Reptile|7690|USD|The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.|https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809 +Egyptian Cobra|Reptile|2390|USD|The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word nāgá (नाग) meaning "cobra". The specific epithet haje is derived from the Arabic word hayya (حية) which literally means small "snake"-according to the Quran or "viper".|https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716 +Round Island Burrowing Boa|Reptile|1790|USD|The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.|https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644 +Nile Crocodile|Reptile|14990|USD|The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.|https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310 +American Alligator|Reptile|17890|USD|The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.|https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010 +Black Mamba|Reptile|2290|USD|The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.|https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636 +Saltwater Crocodile|Reptile|31990|USD|The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz).[35] This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates.[citation needed] Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.|https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609 +Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Réunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleō, a borrowing of the Ancient Greek χαμαιλέων (khamailéōn), a compound of χαμαί (khamaí) "on the ground" and λέων (léōn) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 +King Cobra|Reptile|1990|USD|The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world's longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.|https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332 +Cape Melville Leaf-tailed Gecko|Reptile|99|USD|The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard's distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.|https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111 +Axolotl|Amphibian|99|USD|The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.|https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251 +Cream-backed Poison Frog|Amphibian|49|USD|The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males; this is the most notable difference between the sexes.|https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857 +Tiger Salamander|Amphibian|79|USD|The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.|https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118 +Adelphobates galactonotus|Amphibian|129|USD|Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.|https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest/scale-to-width-down/250?cb=20150626050901 +Bale Mountains Tree Frog|Amphibian|169|USD|The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.|https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022 +Cape Rain Frog|Amphibian|99|USD|The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft's Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.|https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413 +Desert Rain Frog|Amphibian|179|USD|The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.|https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240 +Excidobates captivus|Amphibian|239|USD|Excidobates captivus, also known as the Santiago poison frog or Rio Santiago poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Peru and southern Ecuador. Its natural habitat is tropical moist lowland forests. This frog is black with rows of orange-red spots on its back and yellow spots underneath. With an adult snout-to-vent length of 15 to 17 mm (0.6 to 0.7 in), Excidobates captivus is a very small species of poison frog. It is black with orange-red splotches arranged in a row down either side of the back. It also has small yellow spots above the armpit and groin and further pale yellow spots beneath the chin and scattered on the chest and belly and under the thighs.|https://vignette.wikia.nocookie.net/animals/images/9/90/Captivus5.jpg/revision/latest?cb=20150627075858 +Forest Rain Frog|Amphibian|29|USD|The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.|https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517 +Golden Poison Frog|Amphibian|399|USD|The golden frog is found only in isolated regions of Panama. It's bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.|https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049 +Kihansi Spray Toad|Amphibian|149|USD|The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.|https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143 +Yellow-bellied Poison Frog|Amphibian|239|USD|The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter; both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.|https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228 \ No newline at end of file diff --git a/src/data/categories.csv b/src/data/categories.csv new file mode 100644 index 0000000..6c4faf1 --- /dev/null +++ b/src/data/categories.csv @@ -0,0 +1,4 @@ +Bird|Vertebrate|Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton. +Mammal|Vertebrate|Mammals (class Mammalia /məˈmeɪli.ə/ from Latin mamma "breast") are a clade of endothermic amniotes distinguished from reptiles and birds by the possession of a neocortex (a region of the brain), hair, three middle ear bones and mammary glands. +Reptile|Vertebrate|Reptiles are a group (Reptilia) of tetrapod animals comprising today's turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives. +Amphibian|Vertebrate|The amphibians are tetrapods, a class of vertebrate animals with four limbs. They are non-amniotes, which means that their eggs are not surrounded by the several membranes, some impervious, which enable mammals, reptiles and birds to reproduce on land. \ No newline at end of file diff --git a/src/data/suppliers.csv b/src/data/suppliers.csv new file mode 100644 index 0000000..73cb7be --- /dev/null +++ b/src/data/suppliers.csv @@ -0,0 +1,12 @@ +Montgomery Zoo|Alabama|Montgomery|Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city department, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species. +Alaska Zoo|Alaska|Anchorage|The Alaska Zoo is a zoo in Anchorage, Alaska, located on 25 acres (10 ha) of the Anchorage Hillside. It is a popular attraction in Alaska, with nearly 200,000 visitors per year. The zoo is currently home to more than 100 birds and mammals representing some 50 species. +Phoenix Zoo|Arizona|Phoenix|The Phoenix Zoo opened in 1962 and is the largest privately owned, non-profit zoo in the United States. Located in Phoenix, Arizona, the zoo was founded by Robert Maytag, a member of the Maytag family, and operates on 125 acres (51 ha) of land in the Papago Park area of Phoenix. It has been designated as a Phoenix Point of Pride. +Los Angeles Zoo|California|Los Angeles|The Los Angeles Zoo and Botanical Gardens is a 133-acre (54 ha) zoo founded in 1966 and located in Los Angeles, California. The city of Los Angeles owns the entire zoo, its land and facilities, and the animals. Animal care, grounds maintenance, construction, education, public information, and administrative staff are city employees. +San Diego Zoo|California|San Diego|The San Diego Zoo is a zoo in Balboa Park, San Diego, California, housing more than 3,500 animals of more than 650 species and subspecies. Its parent organization, San Diego Zoo Global, is one of the largest[better source need zoological membership associations in the world, with more than 250,000 member households and 130,000 child memberships, representing more than a half million people. +San Francisco Zoo|California|San Francisco|The San Francisco Zoo is a 100-acre (40 ha) zoo located in the southwestern corner of San Francisco, California, between Lake Merced and the Pacific Ocean along the Great Highway. As of 2016, the zoo housed more than one thousand individual animals, representing more than 250 species. It is noted as the birthplace of Koko the gorilla, and, since 1974, the home of Elly, the oldest black rhinoceros in North America. +Disney's Animal Kingdom|Florida|Bay Lake|Disney's Animal Kingdom is a zoological theme park at the Walt Disney World Resort in Bay Lake, Florida, near Orlando. Owned and operated by The Walt Disney Company through its Parks, Experiences and Consumer Products division, it is the largest theme park in the world, covering 580 acres (230 ha). The park opened on Earth Day, April 22, 1998, and was the fourth theme park built at the resort. +Lion Country Safari|Florida|Loxahatchee|Lion Country Safari is a drive-through safari park and walk-through amusement park located on over 600 acres in Loxahatchee (near West Palm Beach), in Palm Beach County, Florida. Founded in 1967, it claims to be the first 'cageless zoo' in the United States. +Monkey Jungle|Florida|Miami|Monkey Jungle is a 30-acre (12 ha) wildlife park established in 1933 for the exhibition and study of endangered monkeys in semi-natural habitats. Many projects have been conducted at the park, which is a tourist attraction in the Miami, Florida area. The park is in Redland, Florida at Southwest 216th Street/Hainlin Mill Road near Southwest 147th Avenue. +Reptile World Serpentarium|Florida|St. Cloud|Reptile World Serpentarium is a reptile zoo in St. Cloud, Osceola County, Florida. It features more than 75 species of snakes, as well as lizards, crocodiles, alligators, and turtles. It is operated by the herpetologist George Van Horn. In addition to having animals on display, it has venom milking shows. +World Center for Birds of Prey|Idaho|Boise|Built 35 years ago in 1984, the World Center for Birds of Prey is located on 580 acres (2.3 km2) on a hilltop overlooking Boise, south of the airport and east of Kuna. The campus consists of the business offices of The Peregrine Fund, breeding facilities for endangered raptors, the Velma Morrison Interpretive Center, and the Herrick Collections Building, which houses a large research library and the Archives of Falconry. +Yellowstone Bear World|Idaho|Rexburg|Yellowstone Bear World is a privately owned drive-thru wildlife park. It is located in Rexburg, Idaho, near Yellowstone National Park. It was established in 1998. The park holds over 8 species of wildlife indigenous to the Greater Yellowstone Ecosystem. Other attractions in the park include a small amusement park and a petting zoo. Yellowstone Bear World is the only wildlife park in the United States where guests can bottle feed bear cubs. \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index 68bc9ff..7e6b86a 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -24,18 +24,18 @@ public void contextInitialized(ServletContextEvent sce) { SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); //setting up a new supplier - Supplier amazon = new Supplier("Amazon", "Digital content and services"); - supplierDataStore.add(amazon); - Supplier lenovo = new Supplier("Lenovo", "Computers"); - supplierDataStore.add(lenovo); +// Supplier amazon = new Supplier("Amazon", "Digital content and services"); +// supplierDataStore.add(amazon); +// Supplier lenovo = new Supplier("Lenovo", "Computers"); +// supplierDataStore.add(lenovo); //setting up a new product category - ProductCategory tablet = new ProductCategory("Tablet", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); - productCategoryDataStore.add(tablet); +// ProductCategory tablet = new ProductCategory("Tablet", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); +// productCategoryDataStore.add(tablet); //setting up products and printing it - productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); - productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); - productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); +// productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); +// productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); +// productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); } } diff --git a/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java b/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java index 7ab03c5..f152801 100644 --- a/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java +++ b/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java @@ -8,6 +8,8 @@ public interface ProductCategoryDao { void add(ProductCategory category); ProductCategory find(int id); + ProductCategory find(String name); + void remove(int id); List getAll(); diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java index a8cd7be..dba5598 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java @@ -3,11 +3,19 @@ import com.codecool.shop.dao.ProductCategoryDao; import com.codecool.shop.model.ProductCategory; +import com.codecool.shop.model.Supplier; +import jdk.jfr.Category; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; public class ProductCategoryDaoMem implements ProductCategoryDao { + private static final Path PATH = Paths.get("/home/benjamin/Documents/Codecool/oop/4tw/webshop/src/data/categories.csv"); + private List data = new ArrayList<>(); private static ProductCategoryDaoMem instance = null; @@ -15,6 +23,14 @@ public class ProductCategoryDaoMem implements ProductCategoryDao { /* A private Constructor prevents any other class from instantiating. */ private ProductCategoryDaoMem() { + try { + Files.lines(PATH).forEach(line -> { + add(new ProductCategory(line.strip().split("\\|"))); + }); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("No such file or something is wrong with the file... go figure"); + } } public static ProductCategoryDaoMem getInstance() { @@ -35,6 +51,11 @@ public ProductCategory find(int id) { return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); } + @Override + public ProductCategory find(String name) { + return data.stream().filter(productCategory -> productCategory.getName().equals(name)).findFirst().orElse(null); + } + @Override public void remove(int id) { data.remove(find(id)); diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java index df65171..5eec9c8 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java @@ -6,11 +6,17 @@ import com.codecool.shop.model.ProductCategory; import com.codecool.shop.model.Supplier; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class ProductDaoMem implements ProductDao { + private static final Path PATH = Paths.get("/home/benjamin/Documents/Codecool/oop/4tw/webshop/src/data/animals.csv"); private List data = new ArrayList<>(); private static ProductDaoMem instance = null; @@ -18,6 +24,12 @@ public class ProductDaoMem implements ProductDao { /* A private Constructor prevents any other class from instantiating. */ private ProductDaoMem() { + try { + Files.lines(PATH).forEach(line -> add(new Product(line.strip().split("\\|")))); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("No such file or something is wrong with the file... go figure"); + } } public static ProductDaoMem getInstance() { diff --git a/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java index f177f0d..ebdab40 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java @@ -3,17 +3,33 @@ import com.codecool.shop.dao.SupplierDao; import com.codecool.shop.model.Supplier; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.Random; public class SupplierDaoMem implements SupplierDao { + private static final Path PATH = Paths.get("/home/benjamin/Documents/Codecool/oop/4tw/webshop/src/data/suppliers.csv"); + + private int current; private List data = new ArrayList<>(); private static SupplierDaoMem instance = null; /* A private Constructor prevents any other class from instantiating. */ private SupplierDaoMem() { + try { + Files.lines(PATH).forEach(line -> { + add(new Supplier(line.strip().split("\\|"))); + }); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("No such file or something is wrong with the file... go figure"); + } } public static SupplierDaoMem getInstance() { @@ -43,4 +59,12 @@ public void remove(int id) { public List getAll() { return data; } + + public Supplier next() { + return data.get((++current) % data.size()); + } + + public Supplier getRandom() { + return data.get(new Random().nextInt(data.size())); + } } diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java index eaf07a6..177d03c 100644 --- a/src/main/java/com/codecool/shop/model/Product.java +++ b/src/main/java/com/codecool/shop/model/Product.java @@ -1,27 +1,39 @@ package com.codecool.shop.model; +import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; + import java.util.Currency; public class Product extends BaseModel { - private float defaultPrice; + private int defaultPrice; private Currency defaultCurrency; private ProductCategory productCategory; private Supplier supplier; + private String imgLink; - public Product(String name, float defaultPrice, String currencyString, String description, ProductCategory productCategory, Supplier supplier) { + public Product(String name, ProductCategory productCategory, int defaultPrice, String currencyString, String description, String imgLink) { super(name, description); - this.setPrice(defaultPrice, currencyString); - this.setSupplier(supplier); - this.setProductCategory(productCategory); + this.productCategory = productCategory; + this.defaultPrice = defaultPrice; + this.defaultCurrency = Currency.getInstance(currencyString); + this.imgLink = imgLink; } - public float getDefaultPrice() { + public Product(String[] data) { + super(data[0], data[4]); + productCategory = ProductCategoryDaoMem.getInstance().find(data[1]); + defaultPrice = Integer.valueOf(data[2]); + defaultCurrency = Currency.getInstance(data[3]); + imgLink = data[5]; + } + + public int getDefaultPrice() { return defaultPrice; } - public void setDefaultPrice(float defaultPrice) { + public void setDefaultPrice(int defaultPrice) { this.defaultPrice = defaultPrice; } @@ -37,7 +49,7 @@ public String getPrice() { return String.valueOf(this.defaultPrice) + " " + this.defaultCurrency.toString(); } - public void setPrice(float price, String currency) { + public void setPrice(int price, String currency) { this.defaultPrice = price; this.defaultCurrency = Currency.getInstance(currency); } @@ -75,4 +87,8 @@ public String toString() { this.productCategory.getName(), this.supplier.getName()); } + + public String getImgLink() { + return imgLink; + } } diff --git a/src/main/java/com/codecool/shop/model/ProductCategory.java b/src/main/java/com/codecool/shop/model/ProductCategory.java index 704dd9d..601d84a 100644 --- a/src/main/java/com/codecool/shop/model/ProductCategory.java +++ b/src/main/java/com/codecool/shop/model/ProductCategory.java @@ -13,6 +13,11 @@ public ProductCategory(String name, String department, String description) { this.products = new ArrayList<>(); } + public ProductCategory(String[] data) { + super(data[0], data[2]); + department = data[1]; + } + public String getDepartment() { return department; } diff --git a/src/main/java/com/codecool/shop/model/Supplier.java b/src/main/java/com/codecool/shop/model/Supplier.java index 72620aa..82cc807 100644 --- a/src/main/java/com/codecool/shop/model/Supplier.java +++ b/src/main/java/com/codecool/shop/model/Supplier.java @@ -4,10 +4,21 @@ import java.util.List; public class Supplier extends BaseModel { + private String state; + private String city; private List products; - public Supplier(String name, String description) { - super(name); + public Supplier(String name, String state, String city, String description) { + super(name, description); + this.state = state; + this.city = city; + this.products = new ArrayList<>(); + } + + public Supplier(String[] data) { + super(data[0], data[3]); + state = data[1]; + city = data[2]; this.products = new ArrayList<>(); } From 1d9cc89ba742ead8a366950ca872e8ba1e793bc5 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Tue, 14 May 2019 17:46:10 +0200 Subject: [PATCH 13/76] minor changes to animal data, index shows all animals --- src/data/animals.csv | 16 +++++----- .../shop/controller/ProductController.java | 6 ++-- .../java/com/codecool/shop/model/Product.java | 10 +++---- src/main/webapp/static/css/custom.css | 29 +++++++++++++++++++ src/main/webapp/templates/product/index.html | 18 ++++++------ 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/data/animals.csv b/src/data/animals.csv index 020fd0d..999c9d5 100644 --- a/src/data/animals.csv +++ b/src/data/animals.csv @@ -1,6 +1,6 @@ Griffon Vulture|Bird|1990|USD|The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.|https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933 -Bald Eagle|Bird|3490|USD|The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aiētos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.|https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710 -Osprey|Bird|1249|USD|The osprey (Pandion haliaetus) — also called fish eagle, sea hawk, river hawk, and fish hawk — is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.|https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703 +Bald Eagle|Bird|3490|USD|The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aietos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.|https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710 +Osprey|Bird|1249|USD|The osprey (Pandion haliaetus) - also called fish eagle, sea hawk, river hawk, and fish hawk - is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.|https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703 Southern Cassowary|Bird|8990|USD|The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.|https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613 Wilson's Bird-of-paradise|Bird|5499|USD|The Wilson's bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson's bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson's bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).|https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933 Henderson Fruit Dove|Bird|12990|USD|The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.|https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012 @@ -12,16 +12,16 @@ Congo Serpent Eagle|Bird|2990|USD|The Congo serpent eagle (Dryotriorchis spectab Bearded Bellbird|Bird|6990|USD|This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).|https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300 Western Gorilla|Mammal|7290|USD|The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.|https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304 Snow Leopard|Mammal|15490|USD|The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.|https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225 -Humpback Whale|Mammal|39990|USD|The Humpback Whale is a species from the Megaptera genus.Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.|https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349 +Humpback Whale|Mammal|39990|USD|The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.|https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349 Gray Wolf|Mammal|14990|USD|The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They're also highly territorial.|https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608 Moose|Mammal|27990|USD|The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males; other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.|https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550 -Carnivora|Mammal|99990|USD|The Carnivora is an order from the Mammalia class. This group includes cats, dogs, bears, wolves, seals, walruses, otters and weasels. Carnivorans are primarily terrestrial and usually have strong sharp claws, with never fewer than four toes on each foot, and well-developed, prominent canine teeth, cheek teeth that generally have cutting edges. The last premolar of the upper jaw and first molar of the lower are termed the carnassials or sectorial teeth. These are blade-like teeth that occlude with a scissor-like action for shearing and shredding meat. Carnassials are most highly developed in the Felidae and the least developed in the Ursidae.The first carnivoran was a carnivore, and nearly all carnivorans today primarily eat meat.|https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821 +Brown Bear|Mammal|99990|USD|The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it's pet.|https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821 Tiger|Mammal|49990|USD|The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.|https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111 Lion|Mammal|32790|USD|The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.|https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314 -Leopard|Mammal|26790|USD|The leopard (Panthera pardus) (English pronunciation: /ˈlɛpərd/) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard's rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar's do. Both leopards and jaguars that are melanistic are known as black panthers.|https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105 +Leopard|Mammal|26790|USD|The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard's rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar's do. Both leopards and jaguars that are melanistic are known as black panthers.|https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105 Aardvark|Mammal|799|USD|The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or 'thumb'), resulting in four toes, while the rear feet have all five toes.|https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128 Bison|Mammal|37490|USD|The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American; Bison antiquus, B. latifrons, and B. occidentalis. The fourth; the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species; the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)|https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550 -Cheetah|Mammal|24990|USD|The cheetah (pronounced /ˈchē-tə/) (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.|https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800 +Cheetah|Mammal|24990|USD|The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.|https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800 Inland Taipan|Reptile|1290|USD|The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.|https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446 Green Sea Turtle|Reptile|499|USD|The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.|https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939 Komodo Dragon|Reptile|7690|USD|The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.|https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809 @@ -31,13 +31,13 @@ Nile Crocodile|Reptile|14990|USD|The Nile crocodile (Crocodylus niloticus) is an American Alligator|Reptile|17890|USD|The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.|https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010 Black Mamba|Reptile|2290|USD|The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.|https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636 Saltwater Crocodile|Reptile|31990|USD|The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz).[35] This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates.[citation needed] Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.|https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609 -Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Réunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleō, a borrowing of the Ancient Greek χαμαιλέων (khamailéōn), a compound of χαμαί (khamaí) "on the ground" and λέων (léōn) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 +Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleō, a borrowing of the Ancient Greek χαμαιλέων (khamailéōn), a compound of χαμαί (khamaí) "on the ground" and λέων (léōn) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 King Cobra|Reptile|1990|USD|The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world's longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.|https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332 Cape Melville Leaf-tailed Gecko|Reptile|99|USD|The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard's distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.|https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111 Axolotl|Amphibian|99|USD|The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.|https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251 Cream-backed Poison Frog|Amphibian|49|USD|The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males; this is the most notable difference between the sexes.|https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857 Tiger Salamander|Amphibian|79|USD|The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.|https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118 -Adelphobates galactonotus|Amphibian|129|USD|Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.|https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest/scale-to-width-down/250?cb=20150626050901 +Adelphobates galactonotus|Amphibian|129|USD|Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.|https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901 Bale Mountains Tree Frog|Amphibian|169|USD|The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.|https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022 Cape Rain Frog|Amphibian|99|USD|The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft's Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.|https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413 Desert Rain Frog|Amphibian|179|USD|The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.|https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240 diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 53c7df0..25ccd19 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -31,8 +31,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); - context.setVariable("category", productCategoryDataStore.find(1)); - context.setVariable("products", productDataStore.getBy(productCategoryDataStore.find(1))); +// context.setVariable("allCategories", productCategoryDataStore.find(4)); +// context.setVariable("products", productDataStore.getBy(productCategoryDataStore.find(4))); + context.setVariable("categories", productCategoryDataStore); + context.setVariable("products", productDataStore); engine.process("product/index.html", context, resp.getWriter()); } diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java index 177d03c..cb74a50 100644 --- a/src/main/java/com/codecool/shop/model/Product.java +++ b/src/main/java/com/codecool/shop/model/Product.java @@ -6,14 +6,14 @@ public class Product extends BaseModel { - private int defaultPrice; + private float defaultPrice; private Currency defaultCurrency; private ProductCategory productCategory; private Supplier supplier; private String imgLink; - public Product(String name, ProductCategory productCategory, int defaultPrice, String currencyString, String description, String imgLink) { + public Product(String name, ProductCategory productCategory, float defaultPrice, String currencyString, String description, String imgLink) { super(name, description); this.productCategory = productCategory; this.defaultPrice = defaultPrice; @@ -29,11 +29,11 @@ public Product(String[] data) { imgLink = data[5]; } - public int getDefaultPrice() { + public float getDefaultPrice() { return defaultPrice; } - public void setDefaultPrice(int defaultPrice) { + public void setDefaultPrice(float defaultPrice) { this.defaultPrice = defaultPrice; } @@ -49,7 +49,7 @@ public String getPrice() { return String.valueOf(this.defaultPrice) + " " + this.defaultCurrency.toString(); } - public void setPrice(int price, String currency) { + public void setPrice(float price, String currency) { this.defaultPrice = price; this.defaultCurrency = Currency.getInstance(currency); } diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 4e4f29b..57b3857 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -60,3 +60,32 @@ { margin: 0 0 11px; } +h1 { + margin-top: 5%; +} +.crop { + overflow: hidden; + text-align: center; +} +.crop img { + alignment: center; + height: 300px; + /*margin: -75px 0 0 -100px;*/ +} +.animal-description { + height: 200px; + overflow-y: auto; +} +.animal-description::-webkit-scrollbar { + width: 0px; /* Remove scrollbar space */ + background: transparent; /* Optional: just make scrollbar invisible */ +} +.animal-name { + overflow: hidden; + height: 2.5em; + overflow-y: auto; +} +.animal-name::-webkit-scrollbar { + width: 0px; /* Remove scrollbar space */ + background: transparent; /* Optional: just make scrollbar invisible */ +} diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index f9fc8b1..524107b 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -34,18 +34,18 @@

Codecool Shop

-
-
- Category Title -
+
+

Category Title

-
-
- +
+
+
+ +
-

Product name

-

Product description...

+

Product name

+

Product description...

From 835df95a0cb60e018b922b9d2d84f8cf28cecb06 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Tue, 14 May 2019 17:48:21 +0200 Subject: [PATCH 14/76] minor refactor --- .../java/com/codecool/shop/controller/ProductController.java | 2 +- src/main/webapp/templates/product/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 25ccd19..358d3fe 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -33,7 +33,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se WebContext context = new WebContext(req, resp, req.getServletContext()); // context.setVariable("allCategories", productCategoryDataStore.find(4)); // context.setVariable("products", productDataStore.getBy(productCategoryDataStore.find(4))); - context.setVariable("categories", productCategoryDataStore); + context.setVariable("categories", productCategoryDataStore.getAll()); context.setVariable("products", productDataStore); engine.process("product/index.html", context, resp.getWriter()); } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 524107b..2618cfe 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -34,7 +34,7 @@

Codecool Shop

-
+

Category Title

From be1fc87af313c870cc28ab9ad78bed3cefd81cde Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Tue, 14 May 2019 18:06:54 +0200 Subject: [PATCH 15/76] pictures can now be moved with scrolling --- src/main/webapp/static/css/custom.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 57b3857..6169278 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -64,9 +64,13 @@ h1 { margin-top: 5%; } .crop { - overflow: hidden; + overflow: auto; text-align: center; } +.crop::-webkit-scrollbar { + width: 0px; /* Remove scrollbar space */ + background: transparent; /* Optional: just make scrollbar invisible */ +} .crop img { alignment: center; height: 300px; From d4d6f386782acc829480725296bded4d704bb100 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 15 May 2019 09:28:07 +0200 Subject: [PATCH 16/76] Corrected getSumOfPriceBy Product method in Order --- src/main/java/com/codecool/shop/model/Order.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 76ba870..6ff3019 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -55,6 +55,9 @@ public HashMap getProductsOfOrder(){ } public float getSumOfPriceBy(Product product) { - return products.get(product) * product.getDefaultPrice(); + if (products.get(product) != null) { + return products.get(product) * product.getDefaultPrice(); + } + return 0f; } } From 30d96a1e3a064b261b52691d1e1a2b094566ca31 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 15 May 2019 09:29:51 +0200 Subject: [PATCH 17/76] Plus test cases in Class Initializer --- src/main/java/com/codecool/shop/config/Initializer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index 5fff5b7..e8f0d68 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -49,9 +49,14 @@ public void contextInitialized(ServletContextEvent sce) { order.add(product_eins); order.add(product_eins); order.add(product_zwei); + order.reduce(product_eins); order.reduce(product_eins); order.reduce(product_eins); + System.out.println("Num of Products " + order.getNumberOfProducts()); + System.out.println("Sum of price " + order.getSumOfPrice()); + System.out.println("Sum of price of product_zwei " + order.getSumOfPriceBy(product_zwei)); + System.out.println("Sum of price of product_eins" + order.getSumOfPriceBy(product_eins)); } } From 818aac9daab8c04e03d1f31c184cedac6de614f4 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Wed, 15 May 2019 09:31:29 +0200 Subject: [PATCH 18/76] minor changes to animals data --- src/data/animals.csv | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/data/animals.csv b/src/data/animals.csv index 999c9d5..0e94824 100644 --- a/src/data/animals.csv +++ b/src/data/animals.csv @@ -8,7 +8,7 @@ Seram Swiftlet|Bird|799|USD|The Seram swiftlet (Aerodramus ceramensis), is a spe Yap Monarch|Bird|499|USD|The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.|https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519 Harpy Eagle|Bird|999|USD|It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.|https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709 Speckled Piculet|Bird|1390|USD|The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.|https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813 -Congo Serpent Eagle|Bird|2990|USD|The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests’ dark understories.|https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745 +Congo Serpent Eagle|Bird|2990|USD|The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests' dark understories.|https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745 Bearded Bellbird|Bird|6990|USD|This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).|https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300 Western Gorilla|Mammal|7290|USD|The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.|https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304 Snow Leopard|Mammal|15490|USD|The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.|https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225 @@ -25,13 +25,13 @@ Cheetah|Mammal|24990|USD|The cheetah (Acinonyx jubatus), also known as the hunti Inland Taipan|Reptile|1290|USD|The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.|https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446 Green Sea Turtle|Reptile|499|USD|The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.|https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939 Komodo Dragon|Reptile|7690|USD|The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.|https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809 -Egyptian Cobra|Reptile|2390|USD|The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word nāgá (नाग) meaning "cobra". The specific epithet haje is derived from the Arabic word hayya (حية) which literally means small "snake"-according to the Quran or "viper".|https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716 +Egyptian Cobra|Reptile|2390|USD|The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word naga meaning "cobra". The specific epithet haje is derived from the Arabic word hayya which literally means small "snake"-according to the Quran or "viper".|https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716 Round Island Burrowing Boa|Reptile|1790|USD|The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.|https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644 Nile Crocodile|Reptile|14990|USD|The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.|https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310 American Alligator|Reptile|17890|USD|The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.|https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010 Black Mamba|Reptile|2290|USD|The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.|https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636 -Saltwater Crocodile|Reptile|31990|USD|The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz).[35] This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates.[citation needed] Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.|https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609 -Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleō, a borrowing of the Ancient Greek χαμαιλέων (khamailéōn), a compound of χαμαί (khamaí) "on the ground" and λέων (léōn) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 +Saltwater Crocodile|Reptile|31990|USD|The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.|https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609 +Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 King Cobra|Reptile|1990|USD|The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world's longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.|https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332 Cape Melville Leaf-tailed Gecko|Reptile|99|USD|The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard's distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.|https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111 Axolotl|Amphibian|99|USD|The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.|https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251 From 29e48deb6c0de5bd91c461cb524fd529880b69d9 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Wed, 15 May 2019 09:43:10 +0200 Subject: [PATCH 19/76] products now have a supplier assigned to them --- src/main/java/com/codecool/shop/model/Product.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java index cb74a50..cc5e394 100644 --- a/src/main/java/com/codecool/shop/model/Product.java +++ b/src/main/java/com/codecool/shop/model/Product.java @@ -1,6 +1,7 @@ package com.codecool.shop.model; import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; +import com.codecool.shop.dao.implementation.SupplierDaoMem; import java.util.Currency; @@ -27,6 +28,7 @@ public Product(String[] data) { defaultPrice = Integer.valueOf(data[2]); defaultCurrency = Currency.getInstance(data[3]); imgLink = data[5]; + supplier = SupplierDaoMem.getInstance().next(); } public float getDefaultPrice() { @@ -72,6 +74,7 @@ public void setSupplier(Supplier supplier) { this.supplier.addProduct(this); } + @Override public String toString() { return String.format("id: %1$d, " + @@ -91,4 +94,4 @@ public String toString() { public String getImgLink() { return imgLink; } -} +} \ No newline at end of file From 7b3387d62dbbd9f5c527b553466c9dad93bc2590 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Wed, 15 May 2019 10:05:50 +0200 Subject: [PATCH 20/76] changed order class to a singleton, added complete method --- .../com/codecool/shop/config/Initializer.java | 1 + .../java/com/codecool/shop/model/Order.java | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index 2deec8a..e6b490f 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -23,6 +23,7 @@ public void contextInitialized(ServletContextEvent sce) { ProductDao productDataStore = ProductDaoMem.getInstance(); ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); + Order currentOrder = Order.getInstance(); //setting up a new supplier // Supplier amazon = new Supplier("Amazon", "Digital content and services"); diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 6ff3019..da8da33 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -7,16 +7,25 @@ public class Order { private static int instanceCounter; + private static Order instance = null; + private int id; private float sumOfPrice; private int sumOfProducts; - HashMap products; + private Map products; - public Order(){ - this.id = instanceCounter++; + private Order(){ + this.id = ++instanceCounter; products = new HashMap<>(); } + public static Order getInstance() { + if (instance == null) { + instance = new Order(); + } + return instance; + } + public float getSumOfPrice(){ sumOfPrice = 0; for (Map.Entry product : products.entrySet()){ @@ -25,11 +34,7 @@ public float getSumOfPrice(){ return sumOfPrice; } public void add(Product product){ - if(products.get(product) != null){ - products.put(product, products.get(product) + 1); - }else{ - products.put(product, 1); - } + products.merge(product, 1, Integer::sum); } public void reduce(Product product){ @@ -50,7 +55,7 @@ public int getNumberOfProducts(){ return sumOfProducts; } - public HashMap getProductsOfOrder(){ + public Map getProductsOfOrder(){ return products; } @@ -60,4 +65,13 @@ public float getSumOfPriceBy(Product product) { } return 0f; } + + public void complete() { + saveOrderToFile(); + instance = new Order(); + } + + private void saveOrderToFile() { + + } } From f781681858dbfcb0892150ceb3ea7ddc1965b48f Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Wed, 15 May 2019 10:46:00 +0200 Subject: [PATCH 21/76] order date gets saved to json file on order completion, new dependency: Jackson - added to pom.xml --- pom.xml | 5 +++ .../implementation/ProductCategoryDaoMem.java | 2 +- .../dao/implementation/ProductDaoMem.java | 2 +- .../dao/implementation/SupplierDaoMem.java | 2 +- .../java/com/codecool/shop/model/Order.java | 34 +++++++++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 83a7a52..0468ddb 100644 --- a/pom.xml +++ b/pom.xml @@ -65,5 +65,10 @@ thymeleaf 3.0.9.RELEASE + + com.fasterxml.jackson.core + jackson-databind + 2.3.1 + diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java index dba5598..75d8fb9 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java @@ -14,7 +14,7 @@ import java.util.List; public class ProductCategoryDaoMem implements ProductCategoryDao { - private static final Path PATH = Paths.get("/home/benjamin/Documents/Codecool/oop/4tw/webshop/src/data/categories.csv"); + private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/categories.csv"); private List data = new ArrayList<>(); diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java index 5eec9c8..749ec53 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; public class ProductDaoMem implements ProductDao { - private static final Path PATH = Paths.get("/home/benjamin/Documents/Codecool/oop/4tw/webshop/src/data/animals.csv"); + private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/animals.csv"); private List data = new ArrayList<>(); private static ProductDaoMem instance = null; diff --git a/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java index ebdab40..9a0c440 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java @@ -13,7 +13,7 @@ public class SupplierDaoMem implements SupplierDao { - private static final Path PATH = Paths.get("/home/benjamin/Documents/Codecool/oop/4tw/webshop/src/data/suppliers.csv"); + private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/suppliers.csv"); private int current; private List data = new ArrayList<>(); diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index da8da33..4e60a32 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -1,5 +1,20 @@ package com.codecool.shop.model; +import com.codecool.shop.dao.ProductCategoryDao; +import com.codecool.shop.dao.ProductDao; +import com.codecool.shop.dao.SupplierDao; +import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; +import com.codecool.shop.dao.implementation.ProductDaoMem; +import com.codecool.shop.dao.implementation.SupplierDaoMem; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -9,6 +24,8 @@ public class Order { private static int instanceCounter; private static Order instance = null; + private static final String FOLDER_PATH = System.getProperty("user.dir") + "/orders/"; + private int id; private float sumOfPrice; private int sumOfProducts; @@ -72,6 +89,23 @@ public void complete() { } private void saveOrderToFile() { + ObjectMapper mapper = new ObjectMapper(); + DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); + + try { + mapper.writeValue(new File(FOLDER_PATH + id + "_" + dateFormat.format(new Date()) + ".json"), instance); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static void main(String[] args) { + Order order = Order.getInstance(); + ProductDao productDataStore = ProductDaoMem.getInstance(); + ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); + SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); + productDataStore.getAll().forEach(order::add); + productDataStore.getAll().forEach(order::add); + order.complete(); } } From 27bb023e87af03434fabbeb1c58206ced7aac66d Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Wed, 15 May 2019 11:01:10 +0200 Subject: [PATCH 22/76] added confirmed and paid field to order class, added main method for testing purposes to order class --- .../java/com/codecool/shop/model/Order.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 4e60a32..225e05e 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -10,8 +10,6 @@ import java.io.File; import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -27,8 +25,10 @@ public class Order { private static final String FOLDER_PATH = System.getProperty("user.dir") + "/orders/"; private int id; - private float sumOfPrice; + private float priceSum; private int sumOfProducts; + private boolean confirmed; + private boolean paid; private Map products; private Order(){ @@ -43,13 +43,6 @@ public static Order getInstance() { return instance; } - public float getSumOfPrice(){ - sumOfPrice = 0; - for (Map.Entry product : products.entrySet()){ - sumOfPrice += product.getKey().getDefaultPrice() * product.getValue(); - } - return sumOfPrice; - } public void add(Product product){ products.merge(product, 1, Integer::sum); } @@ -64,6 +57,18 @@ public void reduce(Product product){ } } + public int getId() { + return id; + } + + public float getPriceSum(){ + priceSum = 0; + for (Map.Entry product : products.entrySet()){ + priceSum += product.getKey().getDefaultPrice() * product.getValue(); + } + return priceSum; + } + public int getNumberOfProducts(){ sumOfProducts = 0; for(int value : products.values()){ @@ -72,6 +77,14 @@ public int getNumberOfProducts(){ return sumOfProducts; } + public boolean isConfirmed() { + return confirmed; + } + + public boolean isPaid() { + return paid; + } + public Map getProductsOfOrder(){ return products; } @@ -84,6 +97,8 @@ public float getSumOfPriceBy(Product product) { } public void complete() { + confirmed = true; + paid = true; saveOrderToFile(); instance = new Order(); } @@ -100,12 +115,12 @@ private void saveOrderToFile() { } public static void main(String[] args) { - Order order = Order.getInstance(); ProductDao productDataStore = ProductDaoMem.getInstance(); ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); - productDataStore.getAll().forEach(order::add); - productDataStore.getAll().forEach(order::add); - order.complete(); + Order currentOrder = Order.getInstance(); + + productDataStore.getAll().forEach(currentOrder::add); + currentOrder.complete(); } } From d167326afd950a773f940db6dfeb8098685a0b19 Mon Sep 17 00:00:00 2001 From: Lizi Boros Date: Wed, 15 May 2019 11:07:05 +0200 Subject: [PATCH 23/76] Filters back-end implemented && tested --- .../com/codecool/shop/config/Initializer.java | 5 +++ .../shop/controller/ProductController.java | 37 ++++++++++++++++++- .../com/codecool/shop/dao/ProductDao.java | 1 + .../dao/implementation/ProductDaoMem.java | 5 +++ src/main/webapp/templates/product/index.html | 14 +++---- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index d9aad63..e0fa922 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -28,17 +28,22 @@ public void contextInitialized(ServletContextEvent sce) { supplierDataStore.add(amazon); Supplier lenovo = new Supplier("Lenovo", "Computers"); supplierDataStore.add(lenovo); + Supplier apple = new Supplier("Apple", "sdhgsjd"); + supplierDataStore.add(apple); //setting up a new product category ProductCategory tablet = new ProductCategory("Tablet", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); ProductCategory tablet2 = new ProductCategory("Tablet2", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); + ProductCategory phone = new ProductCategory("Phone", "Hardware", "kdgfjhkd"); productCategoryDataStore.add(tablet); productCategoryDataStore.add(tablet2); + productCategoryDataStore.add(phone); //setting up products and printing it productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); productDataStore.add(new Product("random", 8345349, "USD", "lalalla.", tablet2, amazon)); + productDataStore.add(new Product("testtttt", 352352, "USD", "hello", phone, apple)); } } diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 4f5214a..88c2ab7 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -7,6 +7,8 @@ import com.codecool.shop.dao.implementation.ProductDaoMem; import com.codecool.shop.config.TemplateEngineUtil; import com.codecool.shop.dao.implementation.SupplierDaoMem; +import com.codecool.shop.model.ProductCategory; +import com.codecool.shop.model.Supplier; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -34,9 +36,40 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); - context.setVariable("suppliers", supplierDao.getAll()); - context.setVariable("products", productDataStore.getAll()); + + ProductCategory category = null; + + String categoryId = (req.getParameter("category") != null) ? req.getParameter("category") : ""; + try { + category = productCategoryDataStore.find(Integer.parseInt(categoryId)); + } catch (NumberFormatException e) { + category = new ProductCategory("Products", "Default", "Default description"); + } + + Supplier supplier = null; + + String supplierId = (req.getParameter("supplier") != null) ? req.getParameter("supplier") : ""; + try { + supplier = supplierDao.find(Integer.parseInt(supplierId)); + } catch (NumberFormatException e) { + supplier = new Supplier("Default supplier", "Default description"); + } + + context.setVariable("category", category); +// context.setVariable("supplier", supplier); context.setVariable("categories", productCategoryDataStore.getAll()); + context.setVariable("suppliers", supplierDao.getAll()); + + if (category.getName().equals("Products") && !supplier.getName().equals("Default supplier")) { + context.setVariable("products", productDataStore.getBy(supplier)); + } else if (!category.getName().equals("Products") && supplier.getName().equals("Default supplier")) { + context.setVariable("products", productDataStore.getBy(category)); + } else if (category.getName().equals("Products") && supplier.getName().equals("Default supplier")) { + context.setVariable("products", productDataStore.getAll()); + } else { + context.setVariable("products", productDataStore.getBy(supplier, category)); + } + engine.process("product/index.html", context, resp.getWriter()); } diff --git a/src/main/java/com/codecool/shop/dao/ProductDao.java b/src/main/java/com/codecool/shop/dao/ProductDao.java index 82074b5..e26d3b2 100644 --- a/src/main/java/com/codecool/shop/dao/ProductDao.java +++ b/src/main/java/com/codecool/shop/dao/ProductDao.java @@ -15,5 +15,6 @@ public interface ProductDao { List getAll(); List getBy(Supplier supplier); List getBy(ProductCategory productCategory); + List getBy(Supplier supplier, ProductCategory productCategory); } diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java index df65171..fc60174 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java @@ -57,4 +57,9 @@ public List getBy(Supplier supplier) { public List getBy(ProductCategory productCategory) { return data.stream().filter(t -> t.getProductCategory().equals(productCategory)).collect(Collectors.toList()); } + + @Override + public List getBy(Supplier supplier, ProductCategory productCategory) { + return data.stream().filter(t -> t.getSupplier().equals(supplier) && t.getProductCategory().equals(productCategory)).collect(Collectors.toList()); + } } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 90810ce..a1425bf 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -36,7 +36,7 @@

Codecool Shop

- Products + Products
@@ -49,24 +49,24 @@

Codecool Shop

-
+
-
- +
-
- +
+
-
From 646cee6ab12f9c2c5f20ccd6403e3b36a1b5cb0c Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Wed, 15 May 2019 11:11:07 +0200 Subject: [PATCH 24/76] shopping cart page --- .../com/codecool/shop/config/Initializer.java | 18 ----- .../shop/controller/ProductController.java | 4 +- .../controller/ShoppingCartController.java | 50 ++++++++++++++ src/main/webapp/templates/cart/cart.html | 66 +++++++++++++++++++ .../webapp/templates/checkout/checkout.html | 29 ++++++++ src/main/webapp/templates/product/index.html | 1 + 6 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/codecool/shop/controller/ShoppingCartController.java create mode 100644 src/main/webapp/templates/cart/cart.html create mode 100644 src/main/webapp/templates/checkout/checkout.html diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index e8f0d68..3c2d093 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -39,24 +39,6 @@ public void contextInitialized(ServletContextEvent sce) { productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); - //setting up new order - Order order = new Order(); - //testing the order methods - Product product_eins = new Product("Something", 20f, "USD", "nope", tablet, amazon); - Product product_zwei = new Product("Something else", 25f, "USD", "nope and nope", tablet, lenovo); - - order.add(product_eins); - order.add(product_eins); - order.add(product_zwei); - - order.reduce(product_eins); - order.reduce(product_eins); - order.reduce(product_eins); - - System.out.println("Num of Products " + order.getNumberOfProducts()); - System.out.println("Sum of price " + order.getSumOfPrice()); - System.out.println("Sum of price of product_zwei " + order.getSumOfPriceBy(product_zwei)); - System.out.println("Sum of price of product_eins" + order.getSumOfPriceBy(product_eins)); } } diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 53c7df0..14945cf 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -1,10 +1,10 @@ package com.codecool.shop.controller; +import com.codecool.shop.config.TemplateEngineUtil; import com.codecool.shop.dao.ProductCategoryDao; import com.codecool.shop.dao.ProductDao; import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; import com.codecool.shop.dao.implementation.ProductDaoMem; -import com.codecool.shop.config.TemplateEngineUtil; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -14,8 +14,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; @WebServlet(urlPatterns = {"/"}) public class ProductController extends HttpServlet { diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java new file mode 100644 index 0000000..d67b7d9 --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -0,0 +1,50 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.dao.ProductCategoryDao; +import com.codecool.shop.dao.ProductDao; +import com.codecool.shop.dao.SupplierDao; +import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; +import com.codecool.shop.dao.implementation.ProductDaoMem; +import com.codecool.shop.dao.implementation.SupplierDaoMem; +import com.codecool.shop.model.Product; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import com.codecool.shop.model.Order; + + +@WebServlet(urlPatterns = {"/shopping-cart"}) +public class ShoppingCartController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + ProductDao productDataStore = ProductDaoMem.getInstance(); + ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); + SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); + + Order order = new Order(); + + //testing the order methods + Product product_eins = new Product("Something", 20f, "USD", "nope", productCategoryDataStore.find(1), supplierDataStore.find(1)); + Product product_zwei = new Product("Something else", 25f, "USD", "nope and nope", productCategoryDataStore.find(1), supplierDataStore.find(1)); + + order.add(product_eins); + order.add(product_eins); + order.add(product_zwei); + + + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + context.setVariable("", productCategoryDataStore.find(1)); + context.setVariable("cart", order); + engine.process("cart/cart.html", context, resp.getWriter()); + } + +} diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html new file mode 100644 index 0000000..5ac150d --- /dev/null +++ b/src/main/webapp/templates/cart/cart.html @@ -0,0 +1,66 @@ + + + + + + + + Shopping Cart + + + + + + + + + + + + + + + + + + + + +
+

Cart

+
+ +
+
+
+
+ + + + + + + + + + + + + +
NameQuantiySum PriceUnit Price
Product nameQuantitySumPrice of ItemUnit pirce
+
+
+
+
+

Sum Of Price

+
+
+ +
+ + + \ No newline at end of file diff --git a/src/main/webapp/templates/checkout/checkout.html b/src/main/webapp/templates/checkout/checkout.html new file mode 100644 index 0000000..d02471e --- /dev/null +++ b/src/main/webapp/templates/checkout/checkout.html @@ -0,0 +1,29 @@ + + + + + Checkout + + +
+

Checkout details

+
+
+
+ + + +

Billing adress

+ + + + +

Shipping adress

+ + + + +
+
+ + \ No newline at end of file diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index f9fc8b1..6c4d554 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -57,6 +57,7 @@

Product name

+ Shopping Cart
From 91a6f0d85ccac2f4a9b076f7f5d5b73207df019e Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Wed, 15 May 2019 13:00:33 +0200 Subject: [PATCH 25/76] working --- .../controller/ShoppingCartController.java | 13 +--------- .../java/com/codecool/shop/model/Order.java | 24 +++++++++---------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index d67b7d9..febe98a 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -29,21 +29,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); - Order order = new Order(); - - //testing the order methods - Product product_eins = new Product("Something", 20f, "USD", "nope", productCategoryDataStore.find(1), supplierDataStore.find(1)); - Product product_zwei = new Product("Something else", 25f, "USD", "nope and nope", productCategoryDataStore.find(1), supplierDataStore.find(1)); - - order.add(product_eins); - order.add(product_eins); - order.add(product_zwei); - - TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); context.setVariable("", productCategoryDataStore.find(1)); - context.setVariable("cart", order); + context.setVariable("cart", Order.getInstance()); engine.process("cart/cart.html", context, resp.getWriter()); } diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 971eb22..225e05e 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -6,7 +6,7 @@ import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; import com.codecool.shop.dao.implementation.ProductDaoMem; import com.codecool.shop.dao.implementation.SupplierDaoMem; -//import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; import java.io.IOException; @@ -99,20 +99,20 @@ public float getSumOfPriceBy(Product product) { public void complete() { confirmed = true; paid = true; -// saveOrderToFile(); + saveOrderToFile(); instance = new Order(); } -// private void saveOrderToFile() { -// ObjectMapper mapper = new ObjectMapper(); -// DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); -// -// try { -// mapper.writeValue(new File(FOLDER_PATH + id + "_" + dateFormat.format(new Date()) + ".json"), instance); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } + private void saveOrderToFile() { + ObjectMapper mapper = new ObjectMapper(); + DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); + + try { + mapper.writeValue(new File(FOLDER_PATH + id + "_" + dateFormat.format(new Date()) + ".json"), instance); + } catch (IOException e) { + e.printStackTrace(); + } + } public static void main(String[] args) { ProductDao productDataStore = ProductDaoMem.getInstance(); From 4ec0158bd76781f5ac0c8a2b11233115cdf4cba1 Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Wed, 15 May 2019 13:47:24 +0200 Subject: [PATCH 26/76] Add button working --- .../com/codecool/shop/controller/ProductController.java | 6 ++++++ .../codecool/shop/controller/ShoppingCartController.java | 1 + src/main/webapp/templates/cart/cart.html | 2 +- src/main/webapp/templates/product/index.html | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 15e7531..6a78911 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -5,6 +5,7 @@ import com.codecool.shop.dao.ProductDao; import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; import com.codecool.shop.dao.implementation.ProductDaoMem; +import com.codecool.shop.model.Order; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -26,6 +27,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se // Map params = new HashMap<>(); // params.put("category", productCategoryDataStore.find(1)); // params.put("products", productDataStore.getBy(productCategoryDataStore.find(1))); + if (req.getParameter("id") != null){ + int productId = Integer.valueOf(req.getParameter("id")); + Order.getInstance().add(productDataStore.find(productId)); + } + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index febe98a..bc62be3 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -29,6 +29,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); context.setVariable("", productCategoryDataStore.find(1)); diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 5ac150d..280c02f 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -56,7 +56,7 @@

Cart

-

Sum Of Price

+

Sum Of Price

diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 189b6fc..4223707 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -52,7 +52,7 @@

Product name

100 USD

From 5a108cbc4a5394af85eb33debc439c03c3d88582 Mon Sep 17 00:00:00 2001 From: Lizi Boros Date: Wed, 15 May 2019 13:53:23 +0200 Subject: [PATCH 27/76] Filter refactored --- .../shop/controller/ProductController.java | 59 ++++++++++++------- src/main/webapp/templates/product/index.html | 3 - 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 6844f90..67bc9bb 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -26,13 +26,45 @@ public class ProductController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - ProductDao productDataStore = ProductDaoMem.getInstance(); ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); SupplierDao supplierDao = SupplierDaoMem.getInstance(); TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); + ProductCategory category = getProductCategory(req, productCategoryDataStore); + Supplier supplier = getSupplier(req, supplierDao); + + context.setVariable("category", category); + context.setVariable("categories", productCategoryDataStore.getAll()); + context.setVariable("suppliers", supplierDao.getAll()); + filterProducts(category, supplier, context); + engine.process("product/index.html", context, resp.getWriter()); + } + + + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } + + private void filterProducts(ProductCategory category, Supplier supplier, WebContext context) { + ProductDao productDataStore = ProductDaoMem.getInstance(); + String defaultSupplier = "Default supplier"; + String defaultProduct = "Products"; + + if (category.getName().equals(defaultProduct) && !supplier.getName().equals(defaultSupplier)) { + context.setVariable("products", productDataStore.getBy(supplier)); + } else if (!category.getName().equals(defaultProduct) && supplier.getName().equals(defaultSupplier)) { + context.setVariable("products", productDataStore.getBy(category)); + } else if (category.getName().equals(defaultProduct) && supplier.getName().equals(defaultSupplier)) { + context.setVariable("products", productDataStore.getAll()); + } else { + context.setVariable("products", productDataStore.getBy(supplier, category)); + } + + } + + private ProductCategory getProductCategory(HttpServletRequest req, ProductCategoryDao productCategoryDataStore) { ProductCategory category; String categoryId = (req.getParameter("category") != null) ? req.getParameter("category") : ""; @@ -41,7 +73,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se } catch (NumberFormatException e) { category = new ProductCategory("Products", "Default", "Default description"); } + return category; + } + private Supplier getSupplier(HttpServletRequest req, SupplierDao supplierDao) { Supplier supplier; String supplierId = (req.getParameter("supplier") != null) ? req.getParameter("supplier") : ""; @@ -50,27 +85,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se } catch (NumberFormatException e) { supplier = new Supplier("Default supplier", "Default state", "Default city", "Default description"); } - - context.setVariable("category", category); - context.setVariable("categories", productCategoryDataStore.getAll()); - context.setVariable("suppliers", supplierDao.getAll()); - - if (category.getName().equals("Products") && !supplier.getName().equals("Default supplier")) { - context.setVariable("products", productDataStore.getBy(supplier)); - } else if (!category.getName().equals("Products") && supplier.getName().equals("Default supplier")) { - context.setVariable("products", productDataStore.getBy(category)); - } else if (category.getName().equals("Products") && supplier.getName().equals("Default supplier")) { - context.setVariable("products", productDataStore.getAll()); - } else { - context.setVariable("products", productDataStore.getBy(supplier, category)); - } - - engine.process("product/index.html", context, resp.getWriter()); - } - - - protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - doGet(req, resp); + return supplier; } } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 027539a..f72af17 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -55,9 +55,6 @@

Codecool Shop

-
- Animals -
From 9e36cc5f80e7541ad605c83c2eb5eeb1f1189025 Mon Sep 17 00:00:00 2001 From: Lizi Boros Date: Wed, 15 May 2019 14:34:18 +0200 Subject: [PATCH 28/76] Pom dependency corrected --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 415c26c..746d081 100644 --- a/pom.xml +++ b/pom.xml @@ -65,5 +65,10 @@ thymeleaf 3.0.9.RELEASE + + com.fasterxml.jackson.core + jackson-databind + 2.3.1 + From 202822117303d9517a8e07ed8ea9b9c2e83bb32a Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Wed, 15 May 2019 14:38:11 +0200 Subject: [PATCH 29/76] working with filter feature --- pom.xml | 6 ++++++ src/main/webapp/templates/product/index.html | 9 +++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 415c26c..2ca4254 100644 --- a/pom.xml +++ b/pom.xml @@ -65,5 +65,11 @@ thymeleaf 3.0.9.RELEASE + + com.fasterxml.jackson.core + jackson-databind + 2.3.1 + + diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index a06e37f..809c697 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -33,10 +33,7 @@

Codecool Shop

- -
-

Category Title

- +
-
+
@@ -72,7 +69,7 @@

Product name

100 USD

From b651267a9fae0b0ec9cae316300ccb2f44723d9e Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Wed, 15 May 2019 15:04:49 +0200 Subject: [PATCH 30/76] shopping cart button went on top --- src/main/webapp/static/css/custom.css | 15 +++++++++++++++ src/main/webapp/templates/product/index.html | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 6169278..a7329ed 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -93,3 +93,18 @@ h1 { width: 0px; /* Remove scrollbar space */ background: transparent; /* Optional: just make scrollbar invisible */ } +#ex4 .p1[data-count]:after{ + position:absolute; + right:10%; + top:8%; + content: attr(data-count); + font-size:40%; + padding:.2em; + border-radius:50%; + line-height:1em; + color: white; + background:rgba(255,0,0,.85); + text-align:center; + min-width: 1em; +//font-weight:bold; +} diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 809c697..2d2effd 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -49,6 +49,9 @@

Codecool Shop

+ + Shopping Cart +
From dda4741bcf5312c38bb0c07f51e32c2a52112293 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 15 May 2019 22:03:04 +0200 Subject: [PATCH 31/76] Refactored Index.html --- src/main/webapp/templates/product/index.html | 46 ++++++++++---------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 2d2effd..7382060 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -34,26 +34,27 @@

Codecool Shop

-
-
- - - - - Shopping Cart - -
-
+
+
+ + + + + Shopping Cart + +
+
+
@@ -72,13 +73,14 @@

Product name

100 USD

- Add to Cart +
+ +
-
From 98be8c4d0c5fea620ab10dd454f1ec291ff2755c Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 15 May 2019 22:04:08 +0200 Subject: [PATCH 32/76] Add to Cart with post request --- .../shop/controller/ShoppingCartController.java | 14 ++++++++++++-- src/main/webapp/templates/cart/cart.html | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index bc62be3..4934242 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -25,9 +25,7 @@ public class ShoppingCartController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - ProductDao productDataStore = ProductDaoMem.getInstance(); ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); - SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); @@ -37,4 +35,16 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se engine.process("cart/cart.html", context, resp.getWriter()); } + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + ProductDao productDataStore = ProductDaoMem.getInstance(); + + int productId = Integer.valueOf(req.getParameter("id")); + Order.getInstance().add(productDataStore.find(productId)); + + resp.sendRedirect("/"); + + } + } diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 280c02f..3ffe80e 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -58,6 +58,9 @@

Cart

Sum Of Price

+
From 6bd334748d5ad8cf1f5d6355c53cafab7daf2766 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 08:59:24 +0200 Subject: [PATCH 33/76] Refactored table in shopping cart page --- src/main/webapp/templates/cart/cart.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 3ffe80e..28268ba 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -38,14 +38,14 @@

Cart

- +
- + From c7a75996074c90769107c23e39ddacd5f3154bce Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Thu, 16 May 2019 10:41:50 +0200 Subject: [PATCH 34/76] display cart size --- .../shop/controller/ProductController.java | 1 + src/main/webapp/static/css/custom.css | 29 +++++++++++++------ src/main/webapp/templates/cart/cart.html | 16 +++++----- src/main/webapp/templates/footer.html | 2 +- src/main/webapp/templates/product/index.html | 15 ++++++++-- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 871f8db..c6a1d6c 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -50,6 +50,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se context.setVariable("category", category); context.setVariable("categories", productCategoryDataStore.getAll()); context.setVariable("suppliers", supplierDao.getAll()); + context.setVariable("cart", Order.getInstance()); filterProducts(category, supplier, context); engine.process("product/index.html", context, resp.getWriter()); } diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index a7329ed..0867ba5 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -93,18 +93,29 @@ h1 { width: 0px; /* Remove scrollbar space */ background: transparent; /* Optional: just make scrollbar invisible */ } -#ex4 .p1[data-count]:after{ + + +.fa-stack[data-count]:after{ position:absolute; - right:10%; - top:8%; + right:0%; + top:0%; content: attr(data-count); font-size:40%; - padding:.2em; - border-radius:50%; - line-height:1em; + padding:.6em; + border-radius:999px; + line-height:.75em; color: white; - background:rgba(255,0,0,.85); + color:#DF0000; text-align:center; - min-width: 1em; -//font-weight:bold; + min-width:2em; + font-weight:bold; + background: white; + border-style:solid; +} +.fa-circle { + color:#DF0000; +} + +.red-cart { + color: #DF0000; background:white; } diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 280c02f..83b9c22 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -35,28 +35,30 @@

Cart

-
+
-
Name Quantiy Sum Price Unit Price
Product name Quantity SumPrice of Item
+
- - - - + + + + + +
NameQuantiySum PriceUnit PriceNameQuantiySum PriceUnit Price
Product name Quantity SumPrice of Item Unit pirce
-

Sum Of Price

+

Sum Of Price

diff --git a/src/main/webapp/templates/footer.html b/src/main/webapp/templates/footer.html index 35adb99..734e574 100644 --- a/src/main/webapp/templates/footer.html +++ b/src/main/webapp/templates/footer.html @@ -5,7 +5,7 @@
- © 2016 Codecool Budapest + © 2019 Codecool Budapest
diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 2d2effd..6c9fc0c 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -23,6 +23,8 @@ + + @@ -49,8 +51,17 @@

Codecool Shop

- - Shopping Cart + +
+
+ + + + + +
+ +
From d5b2beb87b600ea162e2040ef2d080dea8236eef Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 10:55:17 +0200 Subject: [PATCH 35/76] Refactored table in shopping cart page --- src/main/webapp/templates/cart/cart.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 28268ba..081d846 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -41,7 +41,7 @@

Cart

- + From 690c01a840c774500a9b655d104d37b280c2d5ef Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Thu, 16 May 2019 10:56:09 +0200 Subject: [PATCH 36/76] display cart size --- src/main/webapp/static/css/custom.css | 6 +++--- src/main/webapp/templates/product/index.html | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 0867ba5..4ab2992 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -105,7 +105,7 @@ h1 { border-radius:999px; line-height:.75em; color: white; - color:#DF0000; + color:#17a2b8; text-align:center; min-width:2em; font-weight:bold; @@ -113,9 +113,9 @@ h1 { border-style:solid; } .fa-circle { - color:#DF0000; + color:#17a2b8; } .red-cart { - color: #DF0000; background:white; + color: #17a2b8; background:white; } diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 6c9fc0c..7ee67c9 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -51,9 +51,9 @@

Codecool Shop

- +
-
+
From f552e72e89dc6b7da02672d7f54252fb49eb1d0f Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Thu, 16 May 2019 11:07:44 +0200 Subject: [PATCH 37/76] Merge into develop --- src/main/webapp/templates/cart/cart.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 83b9c22..2d49ad1 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -36,9 +36,9 @@

Cart

-
+
-
NameQuantiyQuantity Sum Price Unit Price
+
@@ -59,6 +59,7 @@

Cart

Sum Of Price

+
From 9d1fb1afbc8832befb3514bfd50528d7f40a7025 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 11:40:19 +0200 Subject: [PATCH 38/76] Refactored table in shopping cart Controller and Back to shop button added to cart page --- .../com/codecool/shop/controller/ShoppingCartController.java | 2 -- src/main/webapp/templates/cart/cart.html | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index 4934242..49938bd 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -25,12 +25,10 @@ public class ShoppingCartController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); - context.setVariable("", productCategoryDataStore.find(1)); context.setVariable("cart", Order.getInstance()); engine.process("cart/cart.html", context, resp.getWriter()); } diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 2d49ad1..a0cdc50 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -61,6 +61,9 @@

Cart

Sum Of Price

+
From e92002225b69e67052d5ae6ba359ad3ffc37fd8a Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 11:46:49 +0200 Subject: [PATCH 39/76] Refactored cart page --- src/main/webapp/templates/cart/cart.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index a0cdc50..240f866 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -50,7 +50,7 @@

Cart

- +
Name Quantiy Product name Quantity SumPrice of ItemUnit pirceUnit price
From fa292c52035fa3eb0e8cdd85f8e10b3a911a7967 Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 16 May 2019 13:46:27 +0200 Subject: [PATCH 40/76] Edit shopping cart --- pom.xml | 6 +- .../controller/ShoppingCartController.java | 20 +++- src/main/webapp/templates/cart/cart.html | 27 +++-- src/main/webapp/templates/product/index.html | 104 +++++++++--------- 4 files changed, 89 insertions(+), 68 deletions(-) diff --git a/pom.xml b/pom.xml index 746d081..ea4bad1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ war - UTF-8 - 9.4.12.v20180830 + UTF-8 + 9.4.12.v20180830 @@ -71,4 +71,4 @@ 2.3.1 - + \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index 49938bd..3948e99 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -26,7 +26,6 @@ public class ShoppingCartController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); context.setVariable("cart", Order.getInstance()); @@ -38,11 +37,20 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S ProductDao productDataStore = ProductDaoMem.getInstance(); - int productId = Integer.valueOf(req.getParameter("id")); - Order.getInstance().add(productDataStore.find(productId)); - - resp.sendRedirect("/"); + if (req.getParameter("id") != null) { + int productId = Integer.valueOf(req.getParameter("id")); + Order.getInstance().add(productDataStore.find(productId)); + + resp.sendRedirect("/"); + } else if (req.getParameter("add-item-by-id") != null){ + int productId = Integer.valueOf(req.getParameter("add-item-by-id")); + Order.getInstance().add(productDataStore.find(productId)); + doGet(req, resp); + } else if (req.getParameter("reduce-item-by-id") != null){ + int productId = Integer.valueOf(req.getParameter("reduce-item-by-id")); + Order.getInstance().reduce(productDataStore.find(productId)); + doGet(req, resp); + } } - } diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 240f866..898d273 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -41,17 +41,30 @@

Cart

- + - - - - - - + + + + + + + + +
NameQuantiyQuantity Sum Price Unit Price
Product nameQuantitySumPrice of ItemUnit price
Product name +
+ +
+
Quantity + +
+ +
+
SumPrice of ItemUnit price
diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 26af997..a6baca5 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -30,68 +30,68 @@ - +
+
+

Codecool Shop

+
+
+
+
+ + + + +
+
+ + + + -
-

Codecool Shop

-
-
+
+
+
+
+
+ +
- -
- -
- -
-
-
-
-
- -
-
-
-

Product name

-

Product description...

-
-
-
-

100 USD

+
+

Product name

+

Product description...

-
-
- -
+
+
+

100 USD

+
+
+
+ +
+
-
+
From 637d85a9be5eb963e631c8d4043fcc8f2fa16c1e Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 16 May 2019 13:57:01 +0200 Subject: [PATCH 41/76] Formatted table of shopping cart --- src/main/webapp/templates/cart/cart.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 898d273..7e2356b 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -37,8 +37,8 @@

Cart

-
- +
+
@@ -46,6 +46,7 @@

Cart

+
+
Name Quantity Unit Price
Product name @@ -65,6 +66,7 @@

Cart

SumPrice of Item Unit price
From 66b065c58aedb57ae9bcaa0286c29772a60b4a94 Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Thu, 16 May 2019 14:45:44 +0200 Subject: [PATCH 42/76] checkout done, payment in progress --- .../shop/controller/CheckoutController.java | 39 +++++ .../shop/controller/PaymentController.java | 30 ++++ .../controller/ShoppingCartController.java | 1 - .../java/com/codecool/shop/model/Order.java | 64 ++++++++ src/main/webapp/templates/cart/cart.html | 2 +- .../webapp/templates/checkout/checkout.html | 144 +++++++++++++++--- .../webapp/templates/payment/payment.html | 109 +++++++++++++ 7 files changed, 369 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/codecool/shop/controller/CheckoutController.java create mode 100644 src/main/java/com/codecool/shop/controller/PaymentController.java create mode 100644 src/main/webapp/templates/payment/payment.html diff --git a/src/main/java/com/codecool/shop/controller/CheckoutController.java b/src/main/java/com/codecool/shop/controller/CheckoutController.java new file mode 100644 index 0000000..c42efd0 --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/CheckoutController.java @@ -0,0 +1,39 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.model.Order; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(urlPatterns = {"/checkout"}) +public class CheckoutController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + engine.process("checkout/checkout.html", context, resp.getWriter()); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + Order.getInstance().setCustomerName(request.getParameter("ShippingName")); + Order.getInstance().setCustomerEmail(request.getParameter("ShippingEmail")); + Order.getInstance().setCustomerPhone(request.getParameter("ShippingPhone")); + Order.getInstance().setCountry(request.getParameter("ShippingCountry")); + Order.getInstance().setCity(request.getParameter("ShippingCity")); + Order.getInstance().setZip(request.getParameter("ShippingZip")); + Order.getInstance().setAddress(request.getParameter("ShippingAddress")); + + response.sendRedirect("/payment"); + } +} diff --git a/src/main/java/com/codecool/shop/controller/PaymentController.java b/src/main/java/com/codecool/shop/controller/PaymentController.java new file mode 100644 index 0000000..c9489c7 --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/PaymentController.java @@ -0,0 +1,30 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.model.Order; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(urlPatterns = {"/payment"}) +public class PaymentController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + + + + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + context.setVariable("order", Order.getInstance()); + engine.process("payment/payment.html", context, resp.getWriter()); + } + +} diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index 4934242..a9bd145 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -30,7 +30,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); - context.setVariable("", productCategoryDataStore.find(1)); context.setVariable("cart", Order.getInstance()); engine.process("cart/cart.html", context, resp.getWriter()); } diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 225e05e..0abdb7e 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -24,6 +24,14 @@ public class Order { private static final String FOLDER_PATH = System.getProperty("user.dir") + "/orders/"; + private String customerName; + private String customerEmail; + private String customerPhone; + private String country; + private String city; + private String address; + private String zip; + private int id; private float priceSum; private int sumOfProducts; @@ -123,4 +131,60 @@ public static void main(String[] args) { productDataStore.getAll().forEach(currentOrder::add); currentOrder.complete(); } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getCustomerEmail() { + return customerEmail; + } + + public void setCustomerEmail(String customerEmail) { + this.customerEmail = customerEmail; + } + + public String getCustomerPhone() { + return customerPhone; + } + + public void setCustomerPhone(String customerPhone) { + this.customerPhone = customerPhone; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getZip() { + return zip; + } + + public void setZip(String zip) { + this.zip = zip; + } } diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 2d49ad1..d19964a 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -59,7 +59,7 @@

Cart

Sum Of Price

- + Checkout
diff --git a/src/main/webapp/templates/checkout/checkout.html b/src/main/webapp/templates/checkout/checkout.html index d02471e..ce7a678 100644 --- a/src/main/webapp/templates/checkout/checkout.html +++ b/src/main/webapp/templates/checkout/checkout.html @@ -1,29 +1,137 @@ - + - - Checkout + + + + + Codecool Shop + + + + + + + + + + + + + + + + + +

Checkout details

-
-
- - - -

Billing adress

- - - - -

Shipping adress

- - - - +
+ +
+
+

Shipping details

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+

Billing address

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ \ No newline at end of file diff --git a/src/main/webapp/templates/payment/payment.html b/src/main/webapp/templates/payment/payment.html new file mode 100644 index 0000000..5df3746 --- /dev/null +++ b/src/main/webapp/templates/payment/payment.html @@ -0,0 +1,109 @@ + + + + + + + + Codecool Shop + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+

Pay Invoice

+
+
+
+
+
    +
  • +
  • +
  • +
  • +
+
+
+ + + Enter the payment amount +
+
+ + + Enter the name as shown on credit card +
+
+ + + Enter a valid 16 digit card number +
+
+
+
+ + + Enter the expiration date +
+
+
+ +
+ + Enter the 3-digit code on back +
+
+ +
+
+
+
+
+
+ + + +
+
+ +
+
+
+
+
+
+
+ + \ No newline at end of file From 2a81f616586c80019f8128e95fa16d1b72578c86 Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Thu, 16 May 2019 14:58:55 +0200 Subject: [PATCH 43/76] Back button and paymant button working --- src/main/webapp/templates/cart/cart.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 05ae691..f2080b8 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -77,7 +77,7 @@

Sum Checkout

From 1c710cd64dad4bde8979e595368980c63584766c Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Thu, 16 May 2019 15:49:57 +0200 Subject: [PATCH 44/76] payment fields fixed --- .../shop/controller/CheckoutController.java | 2 +- .../codecool/shop/controller/PaymentController.java | 6 ++++++ src/main/webapp/templates/payment/payment.html | 13 +++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/CheckoutController.java b/src/main/java/com/codecool/shop/controller/CheckoutController.java index c42efd0..1b72ed9 100644 --- a/src/main/java/com/codecool/shop/controller/CheckoutController.java +++ b/src/main/java/com/codecool/shop/controller/CheckoutController.java @@ -21,6 +21,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); + context.setVariable("order", Order.getInstance()); engine.process("checkout/checkout.html", context, resp.getWriter()); } @@ -33,7 +34,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) Order.getInstance().setCity(request.getParameter("ShippingCity")); Order.getInstance().setZip(request.getParameter("ShippingZip")); Order.getInstance().setAddress(request.getParameter("ShippingAddress")); - response.sendRedirect("/payment"); } } diff --git a/src/main/java/com/codecool/shop/controller/PaymentController.java b/src/main/java/com/codecool/shop/controller/PaymentController.java index c9489c7..e5b37ae 100644 --- a/src/main/java/com/codecool/shop/controller/PaymentController.java +++ b/src/main/java/com/codecool/shop/controller/PaymentController.java @@ -25,6 +25,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se WebContext context = new WebContext(req, resp, req.getServletContext()); context.setVariable("order", Order.getInstance()); engine.process("payment/payment.html", context, resp.getWriter()); + Order.getInstance().complete(); + } + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.sendRedirect("/"); + } } diff --git a/src/main/webapp/templates/payment/payment.html b/src/main/webapp/templates/payment/payment.html index 5df3746..a660ffb 100644 --- a/src/main/webapp/templates/payment/payment.html +++ b/src/main/webapp/templates/payment/payment.html @@ -51,12 +51,12 @@

Pay Invoice

- + Enter the payment amount
- + Enter the name as shown on credit card
@@ -87,17 +87,14 @@

Pay Invoice

-
- - - -
- +
From 15772bda7aaf21aa9da149b75c084f40d2e718cc Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 20:40:07 +0200 Subject: [PATCH 45/76] Refactored Initializer --- .../com/codecool/shop/config/Initializer.java | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index e6b490f..6db55ad 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -1,16 +1,5 @@ package com.codecool.shop.config; -import com.codecool.shop.dao.ProductCategoryDao; -import com.codecool.shop.dao.ProductDao; -import com.codecool.shop.dao.SupplierDao; -import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; -import com.codecool.shop.dao.implementation.ProductDaoMem; -import com.codecool.shop.dao.implementation.SupplierDaoMem; -import com.codecool.shop.model.Order; -import com.codecool.shop.model.Product; -import com.codecool.shop.model.ProductCategory; -import com.codecool.shop.model.Supplier; - import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; @@ -20,24 +9,6 @@ public class Initializer implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { - ProductDao productDataStore = ProductDaoMem.getInstance(); - ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); - SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); - Order currentOrder = Order.getInstance(); - - //setting up a new supplier -// Supplier amazon = new Supplier("Amazon", "Digital content and services"); -// supplierDataStore.add(amazon); -// Supplier lenovo = new Supplier("Lenovo", "Computers"); -// supplierDataStore.add(lenovo); - - //setting up a new product category -// ProductCategory tablet = new ProductCategory("Tablet", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); -// productCategoryDataStore.add(tablet); - //setting up products and printing it -// productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); -// productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); -// productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); } } From 50344026b8081fe75a7083bc0338861d8298b205 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 20:41:59 +0200 Subject: [PATCH 46/76] Refactored ProductController --- .../java/com/codecool/shop/controller/ProductController.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index c6a1d6c..9250c72 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -31,9 +31,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se ProductDao productDataStore = ProductDaoMem.getInstance(); ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); -// Map params = new HashMap<>(); -// params.put("category", productCategoryDataStore.find(1)); -// params.put("products", productDataStore.getBy(productCategoryDataStore.find(1))); if (req.getParameter("id") != null){ int productId = Integer.valueOf(req.getParameter("id")); Order.getInstance().add(productDataStore.find(productId)); From 3d093a385a6b6fec97022f22f73c045812874788 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 16 May 2019 21:21:30 +0200 Subject: [PATCH 47/76] Refactored index page, CheckOutController, corrected call of Order.getInstance().complete() --- .../com/codecool/shop/controller/CheckoutController.java | 2 -- .../com/codecool/shop/controller/PaymentController.java | 6 +----- src/main/webapp/templates/payment/payment.html | 2 +- src/main/webapp/templates/product/index.html | 1 - 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/CheckoutController.java b/src/main/java/com/codecool/shop/controller/CheckoutController.java index 1b72ed9..86a6915 100644 --- a/src/main/java/com/codecool/shop/controller/CheckoutController.java +++ b/src/main/java/com/codecool/shop/controller/CheckoutController.java @@ -17,8 +17,6 @@ public class CheckoutController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - - TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); context.setVariable("order", Order.getInstance()); diff --git a/src/main/java/com/codecool/shop/controller/PaymentController.java b/src/main/java/com/codecool/shop/controller/PaymentController.java index e5b37ae..0c385f0 100644 --- a/src/main/java/com/codecool/shop/controller/PaymentController.java +++ b/src/main/java/com/codecool/shop/controller/PaymentController.java @@ -17,20 +17,16 @@ public class PaymentController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - - - - TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); context.setVariable("order", Order.getInstance()); engine.process("payment/payment.html", context, resp.getWriter()); - Order.getInstance().complete(); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + Order.getInstance().complete(); resp.sendRedirect("/"); } } diff --git a/src/main/webapp/templates/payment/payment.html b/src/main/webapp/templates/payment/payment.html index a660ffb..b33be18 100644 --- a/src/main/webapp/templates/payment/payment.html +++ b/src/main/webapp/templates/payment/payment.html @@ -40,7 +40,7 @@

Pay Invoice


-
+
  • diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index a6baca5..8d36a07 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -26,7 +26,6 @@ - From 2a1fb733bf45b53c0f01a7c02b9fdbdb2554a49d Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Tue, 28 May 2019 15:06:30 +0200 Subject: [PATCH 48/76] added sql file --- pom.xml | 4 +- src/data/animals.sql | 512 ++++++++++++++++++ .../dao/implementation/ProductDaoMem.java | 3 +- src/main/webapp/static/css/custom.css | 2 +- 4 files changed, 516 insertions(+), 5 deletions(-) create mode 100644 src/data/animals.sql diff --git a/pom.xml b/pom.xml index ea4bad1..20dec9e 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ maven-compiler-plugin 3.7.0 - 1.8 - 1.8 + 11 + 11 diff --git a/src/data/animals.sql b/src/data/animals.sql new file mode 100644 index 0000000..8275541 --- /dev/null +++ b/src/data/animals.sql @@ -0,0 +1,512 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1) +-- Dumped by pg_dump version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +DROP INDEX animals.supplier_id_uindex; +DROP INDEX animals.categories_id_uindex; +DROP INDEX animals.animals_id_uindex; +ALTER TABLE ONLY animals.supplier + DROP CONSTRAINT supplier_pk; +ALTER TABLE ONLY animals.categories + DROP CONSTRAINT categories_pk; +ALTER TABLE ONLY animals.animals + DROP CONSTRAINT animals_pk; +ALTER TABLE animals.supplier + ALTER COLUMN id DROP DEFAULT; +ALTER TABLE animals.categories + ALTER COLUMN id DROP DEFAULT; +ALTER TABLE animals.animals + ALTER COLUMN id DROP DEFAULT; +DROP SEQUENCE animals.supplier_id_seq; +DROP TABLE animals.supplier; +DROP SEQUENCE animals.categories_id_seq; +DROP TABLE animals.categories; +DROP SEQUENCE animals.animals_id_seq; +DROP TABLE animals.animals; +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: animals; Type: TABLE; Schema: animals; Owner: miller +-- + +CREATE TABLE animals.animals +( + id integer NOT NULL, + name text, + species_id integer, + price integer, + currecy text, + description text, + website text +); + + +ALTER TABLE animals.animals + OWNER TO miller; + +-- +-- Name: animals_id_seq; Type: SEQUENCE; Schema: animals; Owner: miller +-- + +CREATE SEQUENCE animals.animals_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE animals.animals_id_seq + OWNER TO miller; + +-- +-- Name: animals_id_seq; Type: SEQUENCE OWNED BY; Schema: animals; Owner: miller +-- + +ALTER SEQUENCE animals.animals_id_seq OWNED BY animals.animals.id; + + +-- +-- Name: categories; Type: TABLE; Schema: animals; Owner: miller +-- + +CREATE TABLE animals.categories +( + id integer NOT NULL, + species text, + groups text, + description text +); + + +ALTER TABLE animals.categories + OWNER TO miller; + +-- +-- Name: categories_id_seq; Type: SEQUENCE; Schema: animals; Owner: miller +-- + +CREATE SEQUENCE animals.categories_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE animals.categories_id_seq + OWNER TO miller; + +-- +-- Name: categories_id_seq; Type: SEQUENCE OWNED BY; Schema: animals; Owner: miller +-- + +ALTER SEQUENCE animals.categories_id_seq OWNED BY animals.categories.id; + + +-- +-- Name: supplier; Type: TABLE; Schema: animals; Owner: miller +-- + +CREATE TABLE animals.supplier +( + id integer NOT NULL, + zoo text, + county text, + city text, + description text +); + + +ALTER TABLE animals.supplier + OWNER TO miller; + +-- +-- Name: supplier_id_seq; Type: SEQUENCE; Schema: animals; Owner: miller +-- + +CREATE SEQUENCE animals.supplier_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE animals.supplier_id_seq + OWNER TO miller; + +-- +-- Name: supplier_id_seq; Type: SEQUENCE OWNED BY; Schema: animals; Owner: miller +-- + +ALTER SEQUENCE animals.supplier_id_seq OWNED BY animals.supplier.id; + + +-- +-- Name: animals id; Type: DEFAULT; Schema: animals; Owner: miller +-- + +ALTER TABLE ONLY animals.animals + ALTER COLUMN id SET DEFAULT nextval('animals.animals_id_seq'::regclass); + + +-- +-- Name: categories id; Type: DEFAULT; Schema: animals; Owner: miller +-- + +ALTER TABLE ONLY animals.categories + ALTER COLUMN id SET DEFAULT nextval('animals.categories_id_seq'::regclass); + + +-- +-- Name: supplier id; Type: DEFAULT; Schema: animals; Owner: miller +-- + +ALTER TABLE ONLY animals.supplier + ALTER COLUMN id SET DEFAULT nextval('animals.supplier_id_seq'::regclass); + +-- +-- Data for Name: animals; Type: TABLE DATA; Schema: animals; Owner: miller +-- + +INSERT INTO animals.animals +VALUES (1, 'Griffon Vulture', 1, 1990, 'USD', + 'The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.', + 'https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933'); +INSERT INTO animals.animals +VALUES (2, 'Bald Eagle', 1, 3490, 'USD', + 'The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aietos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.', + 'https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710'); +INSERT INTO animals.animals +VALUES (3, 'Osprey', 1, 1249, 'USD', + 'The osprey (Pandion haliaetus) - also called fish eagle, sea hawk, river hawk, and fish hawk - is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.', + 'https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703'); +INSERT INTO animals.animals +VALUES (4, 'Southern Cassowary', 1, 8990, 'USD', + 'The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.', + 'https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613'); +INSERT INTO animals.animals +VALUES (5, 'Wilson''s Bird-of-paradise', 1, 5499, 'USD', + 'The Wilson''s bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson''s bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson''s bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).', + 'https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933'); +INSERT INTO animals.animals +VALUES (6, 'Henderson Fruit Dove', 1, 12990, 'USD', + 'The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.', + 'https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012'); +INSERT INTO animals.animals +VALUES (7, 'Seram Swiftlet', 1, 799, 'USD', + 'The Seram swiftlet (Aerodramus ceramensis), is a species of swift in the Apodidae family. It is endemic to Buru and Seram Islands. It used to be considered a subspecies of the Moluccan swiftlet. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical moist montane forests.', + 'https://vignette.wikia.nocookie.net/animals/images/d/d3/Moluccanswift2.jpg/revision/latest?cb=20160826191222'); +INSERT INTO animals.animals +VALUES (8, 'Yap Monarch', 1, 499, 'USD', + 'The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.', + 'https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519'); +INSERT INTO animals.animals +VALUES (9, 'Harpy Eagle', 1, 999, 'USD', + 'It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.', + 'https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709'); +INSERT INTO animals.animals +VALUES (10, 'Speckled Piculet', 1, 1390, 'USD', + 'The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.', + 'https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813'); +INSERT INTO animals.animals +VALUES (11, 'Congo Serpent Eagle', 1, 2990, 'USD', + 'The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests'' dark understories.', + 'https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745'); +INSERT INTO animals.animals +VALUES (12, 'Bearded Bellbird', 1, 6990, 'USD', + 'This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations, breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).', + 'https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300'); +INSERT INTO animals.animals +VALUES (13, 'Western Gorilla', 2, 7290, 'USD', + 'The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.', + 'https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304'); +INSERT INTO animals.animals +VALUES (14, 'Snow Leopard', 2, 15490, 'USD', + 'The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.', + 'https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225'); +INSERT INTO animals.animals +VALUES (15, 'Humpback Whale', 2, 39990, 'USD', + 'The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.', + 'https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349'); +INSERT INTO animals.animals +VALUES (16, 'Gray Wolf', 2, 14990, 'USD', + 'The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They''re also highly territorial.', + 'https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608'); +INSERT INTO animals.animals +VALUES (17, 'Moose', 2, 27990, 'USD', + 'The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males, other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.', + 'https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550'); +INSERT INTO animals.animals +VALUES (18, 'Brown Bear', 2, 99990, 'USD', + 'The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it''s pet.', + 'https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821'); +INSERT INTO animals.animals +VALUES (19, 'Tiger', 2, 49990, 'USD', + 'The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.', + 'https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111'); +INSERT INTO animals.animals +VALUES (20, 'Lion', 2, 32790, 'USD', + 'The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.', + 'https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314'); +INSERT INTO animals.animals +VALUES (21, 'Leopard', 2, 26790, 'USD', + 'The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard''s rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar''s do. Both leopards and jaguars that are melanistic are known as black panthers.', + 'https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105'); +INSERT INTO animals.animals +VALUES (22, 'Aardvark', 2, 799, 'USD', + 'The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or ''thumb''), resulting in four toes, while the rear feet have all five toes.', + 'https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128'); +INSERT INTO animals.animals +VALUES (23, 'Bison', 2, 37490, 'USD', + 'The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American, Bison antiquus, B. latifrons, and B. occidentalis. The fourth, the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species, the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)', + 'https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550'); +INSERT INTO animals.animals +VALUES (24, 'Cheetah', 2, 24990, 'USD', + 'The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.', + 'https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800'); +INSERT INTO animals.animals +VALUES (25, 'Inland Taipan', 3, 1290, 'USD', + 'The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.', + 'https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446'); +INSERT INTO animals.animals +VALUES (26, 'Green Sea Turtle', 3, 499, 'USD', + 'The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.', + 'https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939'); +INSERT INTO animals.animals +VALUES (27, 'Komodo Dragon', 3, 7690, 'USD', + 'The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.', + 'https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809'); +INSERT INTO animals.animals +VALUES (28, 'Egyptian Cobra', 3, 2390, 'USD', + 'The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word naga meaning "cobra". The specific epithet haje is derived from the Arabic word hayya which literally means small "snake"-according to the Quran or "viper".', + 'https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716'); +INSERT INTO animals.animals +VALUES (29, 'Round Island Burrowing Boa', 3, 1790, 'USD', + 'The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.', + 'https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644'); +INSERT INTO animals.animals +VALUES (30, 'Nile Crocodile', 3, 14990, 'USD', + 'The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.', + 'https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310'); +INSERT INTO animals.animals +VALUES (31, 'American Alligator', 3, 17890, 'USD', + 'The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.', + 'https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010'); +INSERT INTO animals.animals +VALUES (32, 'Black Mamba', 3, 2290, 'USD', + 'The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent, mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.', + 'https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636'); +INSERT INTO animals.animals +VALUES (33, 'Saltwater Crocodile', 3, 31990, 'USD', + 'The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.', + 'https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609'); +INSERT INTO animals.animals +VALUES (34, 'Panther chameleon', 3, 1199, 'USD', + 'The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal''s feet. The specific name pardalisrefers to the animals'' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".', + 'https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041'); +INSERT INTO animals.animals +VALUES (35, 'King Cobra', 3, 1990, 'USD', + 'The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world''s longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.', + 'https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332'); +INSERT INTO animals.animals +VALUES (36, 'Cape Melville Leaf-tailed Gecko', 3, 99, 'USD', + 'The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard''s distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.', + 'https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111'); +INSERT INTO animals.animals +VALUES (37, 'Axolotl', 4, 99, 'USD', + 'The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.', + 'https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251'); +INSERT INTO animals.animals +VALUES (38, 'Cream-backed Poison Frog', 4, 49, 'USD', + 'The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males, this is the most notable difference between the sexes.', + 'https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857'); +INSERT INTO animals.animals +VALUES (39, 'Tiger Salamander', 4, 79, 'USD', + 'The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.', + 'https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118'); +INSERT INTO animals.animals +VALUES (40, 'Adelphobates galactonotus', 4, 129, 'USD', + 'Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.', + 'https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901'); +INSERT INTO animals.animals +VALUES (41, 'Bale Mountains Tree Frog', 4, 169, 'USD', + 'The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.', + 'https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022'); +INSERT INTO animals.animals +VALUES (42, 'Cape Rain Frog', 4, 99, 'USD', + 'The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft''s Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.', + 'https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413'); +INSERT INTO animals.animals +VALUES (43, 'Desert Rain Frog', 4, 179, 'USD', + 'The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.', + 'https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240'); +INSERT INTO animals.animals +VALUES (44, 'Excidobates captivus', 4, 239, 'USD', + 'Excidobates captivus, also known as the Santiago poison frog or Rio Santiago poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Peru and southern Ecuador. Its natural habitat is tropical moist lowland forests. This frog is black with rows of orange-red spots on its back and yellow spots underneath. With an adult snout-to-vent length of 15 to 17 mm (0.6 to 0.7 in), Excidobates captivus is a very small species of poison frog. It is black with orange-red splotches arranged in a row down either side of the back. It also has small yellow spots above the armpit and groin and further pale yellow spots beneath the chin and scattered on the chest and belly and under the thighs.', + 'https://vignette.wikia.nocookie.net/animals/images/9/90/Captivus5.jpg/revision/latest?cb=20150627075858'); +INSERT INTO animals.animals +VALUES (45, 'Forest Rain Frog', 4, 29, 'USD', + 'The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.', + 'https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517'); +INSERT INTO animals.animals +VALUES (46, 'Golden Poison Frog', 4, 399, 'USD', + 'The golden frog is found only in isolated regions of Panama. It''s bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.', + 'https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049'); +INSERT INTO animals.animals +VALUES (47, 'Kihansi Spray Toad', 4, 149, 'USD', + 'The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.', + 'https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143'); +INSERT INTO animals.animals +VALUES (48, 'Yellow-bellied Poison Frog', 4, 239, 'USD', + 'The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter, both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.', + 'https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228'); + + +-- +-- Data for Name: categories; Type: TABLE DATA; Schema: animals; Owner: miller +-- + +INSERT INTO animals.categories +VALUES (1, 'Bird', 'Vertebrate', + 'Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton.'); +INSERT INTO animals.categories +VALUES (2, 'Mammal', 'Vertebrate', + 'Mammals (class Mammalia /məˈmeɪli.ə/ from Latin mamma "breast") are a clade of endothermic amniotes distinguished from reptiles and birds by the possession of a neocortex (a region of the brain), hair, three middle ear bones and mammary glands.'); +INSERT INTO animals.categories +VALUES (3, 'Reptile', 'Vertebrate', + 'Reptiles are a group (Reptilia) of tetrapod animals comprising today''s turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives.'); +INSERT INTO animals.categories +VALUES (4, 'Amphibian', 'Vertebrate', + 'The amphibians are tetrapods, a class of vertebrate animals with four limbs. They are non-amniotes, which means that their eggs are not surrounded by the several membranes, some impervious, which enable mammals, reptiles and birds to reproduce on land.'); + + +-- +-- Data for Name: supplier; Type: TABLE DATA; Schema: animals; Owner: miller +-- + +INSERT INTO animals.supplier +VALUES (1, 'Montgomery Zoo', 'Alabama', 'Montgomery', + 'Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city department, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species.'); +INSERT INTO animals.supplier +VALUES (2, 'Alaska Zoo', 'Alaska', 'Anchorage', + 'The Alaska Zoo is a zoo in Anchorage, Alaska, located on 25 acres (10 ha) of the Anchorage Hillside. It is a popular attraction in Alaska, with nearly 200,000 visitors per year. The zoo is currently home to more than 100 birds and mammals representing some 50 species.'); +INSERT INTO animals.supplier +VALUES (3, 'Phoenix Zoo', 'Arizona', 'Phoenix', + 'The Phoenix Zoo opened in 1962 and is the largest privately owned, non-profit zoo in the United States. Located in Phoenix, Arizona, the zoo was founded by Robert Maytag, a member of the Maytag family, and operates on 125 acres (51 ha) of land in the Papago Park area of Phoenix. It has been designated as a Phoenix Point of Pride.'); +INSERT INTO animals.supplier +VALUES (4, 'Los Angeles Zoo', 'California', 'Los Angeles', + 'The Los Angeles Zoo and Botanical Gardens is a 133-acre (54 ha) zoo founded in 1966 and located in Los Angeles, California. The city of Los Angeles owns the entire zoo, its land and facilities, and the animals. Animal care, grounds maintenance, construction, education, public information, and administrative staff are city employees.'); +INSERT INTO animals.supplier +VALUES (5, 'San Diego Zoo', 'California', 'San Diego', + 'The San Diego Zoo is a zoo in Balboa Park, San Diego, California, housing more than 3,500 animals of more than 650 species and subspecies. Its parent organization, San Diego Zoo Global, is one of the largest[better source need zoological membership associations in the world, with more than 250,000 member households and 130,000 child memberships, representing more than a half million people.'); +INSERT INTO animals.supplier +VALUES (6, 'San Francisco Zoo', 'California', 'San Francisco', + 'The San Francisco Zoo is a 100-acre (40 ha) zoo located in the southwestern corner of San Francisco, California, between Lake Merced and the Pacific Ocean along the Great Highway. As of 2016, the zoo housed more than one thousand individual animals, representing more than 250 species. It is noted as the birthplace of Koko the gorilla, and, since 1974, the home of Elly, the oldest black rhinoceros in North America.'); +INSERT INTO animals.supplier +VALUES (7, 'Disney''s Animal Kingdom', 'Florida', 'Bay Lake', + 'Disney''s Animal Kingdom is a zoological theme park at the Walt Disney World Resort in Bay Lake, Florida, near Orlando. Owned and operated by The Walt Disney Company through its Parks, Experiences and Consumer Products division, it is the largest theme park in the world, covering 580 acres (230 ha). The park opened on Earth Day, April 22, 1998, and was the fourth theme park built at the resort.'); +INSERT INTO animals.supplier +VALUES (8, 'Lion Country Safari', 'Florida', 'Loxahatchee', + 'Lion Country Safari is a drive-through safari park and walk-through amusement park located on over 600 acres in Loxahatchee (near West Palm Beach), in Palm Beach County, Florida. Founded in 1967, it claims to be the first ''cageless zoo'' in the United States.'); +INSERT INTO animals.supplier +VALUES (9, 'Monkey Jungle', 'Florida', 'Miami', + 'Monkey Jungle is a 30-acre (12 ha) wildlife park established in 1933 for the exhibition and study of endangered monkeys in semi-natural habitats. Many projects have been conducted at the park, which is a tourist attraction in the Miami, Florida area. The park is in Redland, Florida at Southwest 216th Street/Hainlin Mill Road near Southwest 147th Avenue.'); +INSERT INTO animals.supplier +VALUES (10, 'Reptile World Serpentarium', 'Florida', 'St. Cloud', + 'Reptile World Serpentarium is a reptile zoo in St. Cloud, Osceola County, Florida. It features more than 75 species of snakes, as well as lizards, crocodiles, alligators, and turtles. It is operated by the herpetologist George Van Horn. In addition to having animals on display, it has venom milking shows.'); +INSERT INTO animals.supplier +VALUES (11, 'World Center for Birds of Prey', 'Idaho', 'Boise', + 'Built 35 years ago in 1984, the World Center for Birds of Prey is located on 580 acres (2.3 km2) on a hilltop overlooking Boise, south of the airport and east of Kuna. The campus consists of the business offices of The Peregrine Fund, breeding facilities for endangered raptors, the Velma Morrison Interpretive Center, and the Herrick Collections Building, which houses a large research library and the Archives of Falconry.'); +INSERT INTO animals.supplier +VALUES (12, 'Yellowstone Bear World', 'Idaho', 'Rexburg', + 'Yellowstone Bear World is a privately owned drive-thru wildlife park. It is located in Rexburg, Idaho, near Yellowstone National Park. It was established in 1998. The park holds over 8 species of wildlife indigenous to the Greater Yellowstone Ecosystem. Other attractions in the park include a small amusement park and a petting zoo. Yellowstone Bear World is the only wildlife park in the United States where guests can bottle feed bear cubs.'); + + +-- +-- Name: animals_id_seq; Type: SEQUENCE SET; Schema: animals; Owner: miller +-- + +SELECT pg_catalog.setval('animals.animals_id_seq', 48, true); + + +-- +-- Name: categories_id_seq; Type: SEQUENCE SET; Schema: animals; Owner: miller +-- + +SELECT pg_catalog.setval('animals.categories_id_seq', 4, true); + + +-- +-- Name: supplier_id_seq; Type: SEQUENCE SET; Schema: animals; Owner: miller +-- + +SELECT pg_catalog.setval('animals.supplier_id_seq', 12, true); + + +-- +-- Name: animals animals_pk; Type: CONSTRAINT; Schema: animals; Owner: miller +-- + +ALTER TABLE ONLY animals.animals + ADD CONSTRAINT animals_pk PRIMARY KEY (id); + + +-- +-- Name: categories categories_pk; Type: CONSTRAINT; Schema: animals; Owner: miller +-- + +ALTER TABLE ONLY animals.categories + ADD CONSTRAINT categories_pk PRIMARY KEY (id); + + +-- +-- Name: supplier supplier_pk; Type: CONSTRAINT; Schema: animals; Owner: miller +-- + +ALTER TABLE ONLY animals.supplier + ADD CONSTRAINT supplier_pk PRIMARY KEY (id); + + +-- +-- Name: animals_id_uindex; Type: INDEX; Schema: animals; Owner: miller +-- + +CREATE UNIQUE INDEX animals_id_uindex ON animals.animals USING btree (id); + + +-- +-- Name: categories_id_uindex; Type: INDEX; Schema: animals; Owner: miller +-- + +CREATE UNIQUE INDEX categories_id_uindex ON animals.categories USING btree (id); + + +-- +-- Name: supplier_id_uindex; Type: INDEX; Schema: animals; Owner: miller +-- + +CREATE UNIQUE INDEX supplier_id_uindex ON animals.supplier USING btree (id); + +alter table animals.animals + add constraint animals_species_fk foreign key (species_id) references categories; diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java index 1c766a4..fb1e876 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java @@ -11,7 +11,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -27,8 +26,8 @@ private ProductDaoMem() { try { Files.lines(PATH).forEach(line -> add(new Product(line.strip().split("\\|")))); } catch (IOException e) { - e.printStackTrace(); System.out.println("No such file or something is wrong with the file... go figure"); + e.printStackTrace(); } } diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 4ab2992..9865635 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -73,7 +73,7 @@ h1 { } .crop img { alignment: center; - height: 300px; + height: 250px; /*margin: -75px 0 0 -100px;*/ } .animal-description { From 9d9ecf70af81acb44e07f598328b3bd21c682baf Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 28 May 2019 15:09:33 +0200 Subject: [PATCH 49/76] Junit5 in pom.xml --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index ea4bad1..6c8981f 100644 --- a/pom.xml +++ b/pom.xml @@ -70,5 +70,11 @@ jackson-databind 2.3.1 + + org.junit.jupiter + junit-jupiter-api + 5.3.2 + compile + \ No newline at end of file From 06af66bb7ac4202e7f08913044eb8cdb04bfdf6a Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Tue, 28 May 2019 15:12:32 +0200 Subject: [PATCH 50/76] template for testing ProductDao --- .../codecool/shop/tests/TestProductDao.java | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/main/java/com/codecool/shop/tests/TestProductDao.java diff --git a/src/main/java/com/codecool/shop/tests/TestProductDao.java b/src/main/java/com/codecool/shop/tests/TestProductDao.java new file mode 100644 index 0000000..da575b8 --- /dev/null +++ b/src/main/java/com/codecool/shop/tests/TestProductDao.java @@ -0,0 +1,151 @@ +package com.codecool.shop.tests; + +import com.codecool.shop.dao.ProductDao; +import com.codecool.shop.dao.implementation.ProductDaoMem; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class TestProductDao { + private ProductDao productDao; +// +// /** +// * Make a new instance every time before running a test +// */ +// @BeforeEach +// void setup() { +// ProductDao productDao = new ProductDaoMem.getInstance(); +// } + +// /** +// * Start with the most trivial tests like checking what happens if +// * the FilePartReader parameter is null +// */ +// @Test +// void testWordsArePalindromeWhenFilePartReaderNullShouldThrowNullPointerException() { +// fileWordAnalyzer = new FileWordAnalyzer(null); +// assertThrows(NullPointerException.class, () -> fileWordAnalyzer.getStringsWhichPalindromes()); +// } +// +// /** +// * Normal working of alphabetical ordering +// * @throws IOException +// */ +// @Test +// void testGetWordsOrderedAlphabeticallyWhenProperSetupThenWorkingProperly() throws IOException { +// ArrayList expected = new ArrayList<>(Arrays.asList( +// "All gathering days creeping.", +// "Cattle second under creeping god, whose firmament.", +// "Creature greater great Fly moving. Bring.", +// "Creeping. Whales brought you're.", +// "Day After saw one To rule.", +// "Divided. Face greater good subdue isn't land.", +// "Every lesser don't land.", +// "Fly itself divide forth she'd to. The.", +// "Fruit Shall earth have.", +// "In spirit Whales to unto from. There.", +// "Moved forth, she'd yielding together.", +// "Moved rule isn't moveth grass a meat third.", +// "Moveth days.", +// "Said fowl female together spirit.", +// "Saying night heaven divided Seas darkness yielding divide.", +// "Sore was I ere I saw Eros", +// "There creature second whose light all gathering.", +// "To shall forth in two.", +// "Upon there fowl male.", +// "Warsaw was raw", +// "Xanax" +// )); +// assertEquals(expected, fileWordAnalyzer.getWordsOrderedAlphabetically()); +// } +// +// /** +// * Test the normal working of the substring finder +// * @throws IOException +// */ +// @Test +// void testGetWordsContainingSubstringWhenThereIsMatchThenGivesThemBack() throws IOException { +// ArrayList expected = new ArrayList<>(Arrays.asList( +// "Moved rule isn't moveth grass a meat third.", +// "Moved forth, she'd yielding together.", +// "Moveth days." +// )); +// assertEquals(expected, fileWordAnalyzer.getWordsContainingSubstring("Move")); +// } +// +// /** +// * And don't forget to test when there are no matches for the substring +// * we are searching for +// * @throws IOException +// */ +// @Test +// void testGetWordsContainingSubstringWhenNoMatchThenReturnEmptyList() throws IOException { +// List expected = new ArrayList<>(); +// assertEquals(expected, fileWordAnalyzer.getWordsContainingSubstring("Kamehameha")); +// } +// +// /** +// * The same for the palindromes. This one is the normal way of working +// * @throws IOException +// */ +// @Test +// void testGetStringsWhichPalindromesWhenThereIsMatchThenGivesThemBack() throws IOException { +// ArrayList expected = new ArrayList<>(Arrays.asList( +// "Sore was I ere I saw Eros", +// "Xanax" +// )); +// assertEquals(expected, fileWordAnalyzer.getStringsWhichPalindromes()); +// } +// +// /** +// * There are times when you would need another setup to run before each test +// * but it should test the same class. What to do? +// * Nested test class can be an answer to this. Read about it here: +// * +// * https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested +// * https://howtoprogram.xyz/2016/08/19/junit-5-nested-tests-examples/ +// * +// */ +// @Nested +// class EmptyResultTests { +// @BeforeEach +// void setup() { +// FilePartReader filePartReader = new FilePartReader(); +// filePartReader.setup(TestUtils.TEST_FILE_PATH, 1, 1); +// +// fileWordAnalyzer = new FileWordAnalyzer(filePartReader); +// } +// +// /** +// * It's also a good idea to check what happens if there is only one +// * entry in the FilePartReader. +// * @throws IOException +// */ +// @Test +// void testGetWordsOrderedAlphabeticallyWhenOneLineThenWorksProperly() throws IOException { +// ArrayList expected = new ArrayList<>(Arrays.asList( +// "All gathering days creeping.")); +// assertEquals(expected, fileWordAnalyzer.getWordsOrderedAlphabetically()); +// } +// +// /** +// * The same with palindromes: what happens when no palindromes found? +// * @throws IOException +// */ +// @Test +// void testGetStringsWhichPalindromesWhenNoPalindromeThenGivesEmptyList() throws IOException { +// List expected = new ArrayList<>(); +// assertEquals(expected, fileWordAnalyzer.getStringsWhichPalindromes()); +// } +// } + + /* We could test several more cases: + - the result is only one palindrome/substring + - all of the lines containing palindromes/substrings + - make sure to have words which are almost palindromes. + The one character should be around the center like: "abcdefdcba" or "abcdfedcba" + */ +} From 43ea7cb7be84fce401e85430c822e5d16220bbde Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Wed, 29 May 2019 13:08:11 +0200 Subject: [PATCH 51/76] Registration template --- .../controller/RegistrationController.java | 25 ++++++++ .../templates/registration/registration.html | 59 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/main/java/com/codecool/shop/controller/RegistrationController.java create mode 100644 src/main/webapp/templates/registration/registration.html diff --git a/src/main/java/com/codecool/shop/controller/RegistrationController.java b/src/main/java/com/codecool/shop/controller/RegistrationController.java new file mode 100644 index 0000000..a2b1e4b --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/RegistrationController.java @@ -0,0 +1,25 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(urlPatterns = "/registration") +public class RegistrationController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + engine.process("registration/registration.html", context, resp.getWriter()); + } + +} diff --git a/src/main/webapp/templates/registration/registration.html b/src/main/webapp/templates/registration/registration.html new file mode 100644 index 0000000..530539b --- /dev/null +++ b/src/main/webapp/templates/registration/registration.html @@ -0,0 +1,59 @@ + + + + + + + + Codecool Shop + + + + + + + + + + + + + + + + + + + + +
    +

    Registration

    +
    +
    + +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    +
    + +
    + + + \ No newline at end of file From c71dccfaf25f7574a5ef89e0e4d087101e0dab6e Mon Sep 17 00:00:00 2001 From: TheRandomHero Date: Wed, 29 May 2019 15:03:46 +0200 Subject: [PATCH 52/76] paypal added, and back buttons also --- src/data/animals.csv | 12 ++-- src/main/webapp/static/css/custom.css | 8 +++ src/main/webapp/static/js/paypal.js | 24 ++++++++ src/main/webapp/templates/cart/cart.html | 2 +- .../webapp/templates/checkout/checkout.html | 3 + .../webapp/templates/payment/payment.html | 59 +++++++++++++++++-- 6 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 src/main/webapp/static/js/paypal.js diff --git a/src/data/animals.csv b/src/data/animals.csv index 0e94824..36a2922 100644 --- a/src/data/animals.csv +++ b/src/data/animals.csv @@ -9,18 +9,18 @@ Yap Monarch|Bird|499|USD|The Yap monarch (Monarcha godeffroyi), is a species of Harpy Eagle|Bird|999|USD|It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.|https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709 Speckled Piculet|Bird|1390|USD|The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.|https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813 Congo Serpent Eagle|Bird|2990|USD|The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests' dark understories.|https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745 -Bearded Bellbird|Bird|6990|USD|This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).|https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300 +Bearded Bellbird|Bird|6990|USD|This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations, breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).|https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300 Western Gorilla|Mammal|7290|USD|The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.|https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304 Snow Leopard|Mammal|15490|USD|The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.|https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225 Humpback Whale|Mammal|39990|USD|The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.|https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349 Gray Wolf|Mammal|14990|USD|The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They're also highly territorial.|https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608 -Moose|Mammal|27990|USD|The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males; other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.|https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550 +Moose|Mammal|27990|USD|The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males, other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.|https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550 Brown Bear|Mammal|99990|USD|The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it's pet.|https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821 Tiger|Mammal|49990|USD|The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.|https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111 Lion|Mammal|32790|USD|The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.|https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314 Leopard|Mammal|26790|USD|The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard's rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar's do. Both leopards and jaguars that are melanistic are known as black panthers.|https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105 Aardvark|Mammal|799|USD|The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or 'thumb'), resulting in four toes, while the rear feet have all five toes.|https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128 -Bison|Mammal|37490|USD|The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American; Bison antiquus, B. latifrons, and B. occidentalis. The fourth; the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species; the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)|https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550 +Bison|Mammal|37490|USD|The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American, Bison antiquus, B. latifrons, and B. occidentalis. The fourth, the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species, the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)|https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550 Cheetah|Mammal|24990|USD|The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.|https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800 Inland Taipan|Reptile|1290|USD|The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.|https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446 Green Sea Turtle|Reptile|499|USD|The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.|https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939 @@ -29,13 +29,13 @@ Egyptian Cobra|Reptile|2390|USD|The Egyptian cobra (Naja haje) is a species in t Round Island Burrowing Boa|Reptile|1790|USD|The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.|https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644 Nile Crocodile|Reptile|14990|USD|The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.|https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310 American Alligator|Reptile|17890|USD|The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.|https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010 -Black Mamba|Reptile|2290|USD|The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.|https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636 +Black Mamba|Reptile|2290|USD|The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent, mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.|https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636 Saltwater Crocodile|Reptile|31990|USD|The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.|https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609 Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 King Cobra|Reptile|1990|USD|The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world's longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.|https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332 Cape Melville Leaf-tailed Gecko|Reptile|99|USD|The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard's distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.|https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111 Axolotl|Amphibian|99|USD|The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.|https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251 -Cream-backed Poison Frog|Amphibian|49|USD|The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males; this is the most notable difference between the sexes.|https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857 +Cream-backed Poison Frog|Amphibian|49|USD|The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males, this is the most notable difference between the sexes.|https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857 Tiger Salamander|Amphibian|79|USD|The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.|https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118 Adelphobates galactonotus|Amphibian|129|USD|Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.|https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901 Bale Mountains Tree Frog|Amphibian|169|USD|The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.|https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022 @@ -45,4 +45,4 @@ Excidobates captivus|Amphibian|239|USD|Excidobates captivus, also known as the S Forest Rain Frog|Amphibian|29|USD|The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.|https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517 Golden Poison Frog|Amphibian|399|USD|The golden frog is found only in isolated regions of Panama. It's bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.|https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049 Kihansi Spray Toad|Amphibian|149|USD|The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.|https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143 -Yellow-bellied Poison Frog|Amphibian|239|USD|The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter; both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.|https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228 \ No newline at end of file +Yellow-bellied Poison Frog|Amphibian|239|USD|The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter, both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.|https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228 \ No newline at end of file diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 4ab2992..ccdbd63 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -119,3 +119,11 @@ h1 { .red-cart { color: #17a2b8; background:white; } + +#paypal-img{ + width: 70%; +} + +#nav-tab-paypal{ + display: inline-block; +} diff --git a/src/main/webapp/static/js/paypal.js b/src/main/webapp/static/js/paypal.js new file mode 100644 index 0000000..5b66372 --- /dev/null +++ b/src/main/webapp/static/js/paypal.js @@ -0,0 +1,24 @@ + + paypal.Buttons({ + + // Set up the transaction + createOrder: function(data, actions) { + return actions.order.create({ + purchase_units: [{ + amount: { + value: '0.01' + } + }] + }); + }, + + // Finalize the transaction + onApprove: function(data, actions) { + return actions.order.capture().then(function(details) { + // Show a success message to the buyer + alert('Transaction completed by ' + details.payer.name.given_name + '!'); + }); + } + + + }).render('#paypal-button-container'); diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index f2080b8..874502d 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -77,7 +77,7 @@

    Sum Checkout

- Back to the shop + Back to the shop
diff --git a/src/main/webapp/templates/checkout/checkout.html b/src/main/webapp/templates/checkout/checkout.html index ce7a678..3c2506e 100644 --- a/src/main/webapp/templates/checkout/checkout.html +++ b/src/main/webapp/templates/checkout/checkout.html @@ -109,6 +109,9 @@

Billing address

+
+ Back to the shop +
+ + \ No newline at end of file From 245a05b3dbd3c42ac40e8f37696e7631d3ba5485 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 29 May 2019 15:08:05 +0200 Subject: [PATCH 53/76] tests for getBySupplier and getByProductCategory --- .../codecool/shop/tests/TestProductDao.java | 181 +++++------------- 1 file changed, 44 insertions(+), 137 deletions(-) diff --git a/src/main/java/com/codecool/shop/tests/TestProductDao.java b/src/main/java/com/codecool/shop/tests/TestProductDao.java index da575b8..cd24f1f 100644 --- a/src/main/java/com/codecool/shop/tests/TestProductDao.java +++ b/src/main/java/com/codecool/shop/tests/TestProductDao.java @@ -1,151 +1,58 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.ProductDao; +import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; import com.codecool.shop.dao.implementation.ProductDaoMem; +import com.codecool.shop.dao.implementation.SupplierDaoMem; +import com.codecool.shop.model.Product; +import com.codecool.shop.model.ProductCategory; +import com.codecool.shop.model.Supplier; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestProductDao { private ProductDao productDao; -// -// /** -// * Make a new instance every time before running a test -// */ -// @BeforeEach -// void setup() { -// ProductDao productDao = new ProductDaoMem.getInstance(); -// } -// /** -// * Start with the most trivial tests like checking what happens if -// * the FilePartReader parameter is null -// */ -// @Test -// void testWordsArePalindromeWhenFilePartReaderNullShouldThrowNullPointerException() { -// fileWordAnalyzer = new FileWordAnalyzer(null); -// assertThrows(NullPointerException.class, () -> fileWordAnalyzer.getStringsWhichPalindromes()); -// } -// -// /** -// * Normal working of alphabetical ordering -// * @throws IOException -// */ -// @Test -// void testGetWordsOrderedAlphabeticallyWhenProperSetupThenWorkingProperly() throws IOException { -// ArrayList expected = new ArrayList<>(Arrays.asList( -// "All gathering days creeping.", -// "Cattle second under creeping god, whose firmament.", -// "Creature greater great Fly moving. Bring.", -// "Creeping. Whales brought you're.", -// "Day After saw one To rule.", -// "Divided. Face greater good subdue isn't land.", -// "Every lesser don't land.", -// "Fly itself divide forth she'd to. The.", -// "Fruit Shall earth have.", -// "In spirit Whales to unto from. There.", -// "Moved forth, she'd yielding together.", -// "Moved rule isn't moveth grass a meat third.", -// "Moveth days.", -// "Said fowl female together spirit.", -// "Saying night heaven divided Seas darkness yielding divide.", -// "Sore was I ere I saw Eros", -// "There creature second whose light all gathering.", -// "To shall forth in two.", -// "Upon there fowl male.", -// "Warsaw was raw", -// "Xanax" -// )); -// assertEquals(expected, fileWordAnalyzer.getWordsOrderedAlphabetically()); -// } -// -// /** -// * Test the normal working of the substring finder -// * @throws IOException -// */ -// @Test -// void testGetWordsContainingSubstringWhenThereIsMatchThenGivesThemBack() throws IOException { -// ArrayList expected = new ArrayList<>(Arrays.asList( -// "Moved rule isn't moveth grass a meat third.", -// "Moved forth, she'd yielding together.", -// "Moveth days." -// )); -// assertEquals(expected, fileWordAnalyzer.getWordsContainingSubstring("Move")); -// } -// -// /** -// * And don't forget to test when there are no matches for the substring -// * we are searching for -// * @throws IOException -// */ -// @Test -// void testGetWordsContainingSubstringWhenNoMatchThenReturnEmptyList() throws IOException { -// List expected = new ArrayList<>(); -// assertEquals(expected, fileWordAnalyzer.getWordsContainingSubstring("Kamehameha")); -// } -// -// /** -// * The same for the palindromes. This one is the normal way of working -// * @throws IOException -// */ -// @Test -// void testGetStringsWhichPalindromesWhenThereIsMatchThenGivesThemBack() throws IOException { -// ArrayList expected = new ArrayList<>(Arrays.asList( -// "Sore was I ere I saw Eros", -// "Xanax" -// )); -// assertEquals(expected, fileWordAnalyzer.getStringsWhichPalindromes()); -// } -// -// /** -// * There are times when you would need another setup to run before each test -// * but it should test the same class. What to do? -// * Nested test class can be an answer to this. Read about it here: -// * -// * https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested -// * https://howtoprogram.xyz/2016/08/19/junit-5-nested-tests-examples/ -// * -// */ -// @Nested -// class EmptyResultTests { -// @BeforeEach -// void setup() { -// FilePartReader filePartReader = new FilePartReader(); -// filePartReader.setup(TestUtils.TEST_FILE_PATH, 1, 1); -// -// fileWordAnalyzer = new FileWordAnalyzer(filePartReader); -// } -// -// /** -// * It's also a good idea to check what happens if there is only one -// * entry in the FilePartReader. -// * @throws IOException -// */ -// @Test -// void testGetWordsOrderedAlphabeticallyWhenOneLineThenWorksProperly() throws IOException { -// ArrayList expected = new ArrayList<>(Arrays.asList( -// "All gathering days creeping.")); -// assertEquals(expected, fileWordAnalyzer.getWordsOrderedAlphabetically()); -// } -// -// /** -// * The same with palindromes: what happens when no palindromes found? -// * @throws IOException -// */ -// @Test -// void testGetStringsWhichPalindromesWhenNoPalindromeThenGivesEmptyList() throws IOException { -// List expected = new ArrayList<>(); -// assertEquals(expected, fileWordAnalyzer.getStringsWhichPalindromes()); -// } -// } + /** + * Make a new instance every time before running a test + */ + @BeforeEach + void setup() { + productDao = ProductDaoMem.getInstance(); + } - /* We could test several more cases: - - the result is only one palindrome/substring - - all of the lines containing palindromes/substrings - - make sure to have words which are almost palindromes. - The one character should be around the center like: "abcdefdcba" or "abcdfedcba" - */ + @Test + void testGetBySupplier() { + Supplier supplier = SupplierDaoMem.getInstance().find(1); + List expected = new ArrayList<>(); + expected.add(productDao.find(12)); + expected.add(productDao.find(24)); + expected.add(productDao.find(36)); + expected.add(productDao.find(48)); + assertEquals(productDao.getBy(supplier), expected); + } + + @Test + void testGetByProductCategory() { + ProductCategory productCategory = ProductCategoryDaoMem.getInstance().find(1); + List expected = new ArrayList<>(); + expected.add(productDao.find(1)); + expected.add(productDao.find(2)); + expected.add(productDao.find(3)); + expected.add(productDao.find(4)); + expected.add(productDao.find(5)); + expected.add(productDao.find(6)); + expected.add(productDao.find(7)); + expected.add(productDao.find(8)); + expected.add(productDao.find(9)); + expected.add(productDao.find(10)); + expected.add(productDao.find(11)); + expected.add(productDao.find(12)); + assertEquals(productDao.getBy(productCategory), expected); + } } From d77f546e5071aa8cf6dcb46c1c77abe141af9db5 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 29 May 2019 18:27:53 +0200 Subject: [PATCH 54/76] Empty shopping cart after payment (correcting merge from develop) --- src/main/webapp/templates/payment/payment.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/webapp/templates/payment/payment.html b/src/main/webapp/templates/payment/payment.html index c9acdba..962981a 100644 --- a/src/main/webapp/templates/payment/payment.html +++ b/src/main/webapp/templates/payment/payment.html @@ -53,7 +53,6 @@

Pay Invoice

-
+
diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 8d36a07..b1e2328 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -36,16 +36,16 @@

Codecool Shop

- + +
+
- + +
+
@@ -66,24 +66,24 @@

Codecool Shop

-
-
+
+
- +
-

Product name

-

Product description...

+

Product name

+

Product description...

-

100 USD

+

100 USD

- +
From e5c05dcfa5c3dde18c2a25e4693e21356e1e182c Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Thu, 30 May 2019 09:50:43 +0200 Subject: [PATCH 56/76] added id column to animals table --- src/data/database/animal.sql | 98 ++++++++++--------- .../shop/controller/ProductController.java | 6 +- .../controller/ShoppingCartController.java | 2 +- .../dao/implementation/DB/AnimalDaoDB.java | 46 +++++++++ .../{ => Mem}/AnimalDaoMem.java | 2 +- .../{ => Mem}/SpeciesDaoMem.java | 2 +- .../implementation/{ => Mem}/ZooDaoMem.java | 3 +- .../shop/databaseHandler/CodecoolShopDb.java | 7 +- .../java/com/codecool/shop/model/Animal.java | 4 +- .../java/com/codecool/shop/model/Order.java | 6 +- 10 files changed, 112 insertions(+), 64 deletions(-) create mode 100644 src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java rename src/main/java/com/codecool/shop/dao/implementation/{ => Mem}/AnimalDaoMem.java (97%) rename src/main/java/com/codecool/shop/dao/implementation/{ => Mem}/SpeciesDaoMem.java (97%) rename src/main/java/com/codecool/shop/dao/implementation/{ => Mem}/ZooDaoMem.java (95%) diff --git a/src/data/database/animal.sql b/src/data/database/animal.sql index 3567225..b54fbdd 100644 --- a/src/data/database/animal.sql +++ b/src/data/database/animal.sql @@ -1,6 +1,7 @@ drop table if exists animals; CREATE TABLE "animals" ( + "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, "name" TEXT, "species" TEXT constraint animals_species references species, "price" INT, @@ -8,52 +9,53 @@ CREATE TABLE "animals" ( "description" TEXT, "img_url" TEXT ); + INSERT INTO "animals" VALUES - ('Griffon Vulture','Bird',1990,'USD','The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.','https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933'), - ('Bald Eagle','Bird',3490,'USD','The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aietos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.','https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710'), - ('Osprey','Bird',1249,'USD','The osprey (Pandion haliaetus) - also called fish eagle, sea hawk, river hawk, and fish hawk - is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.','https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703'), - ('Southern Cassowary','Bird',8990,'USD','The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.','https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613'), - ('Wilson''s Bird-of-paradise','Bird',5499,'USD','The Wilson''s bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson''s bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson''s bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).','https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933'), - ('Henderson Fruit Dove','Bird',12990,'USD','The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.','https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012'), - ('Seram Swiftlet','Bird',799,'USD','The Seram swiftlet (Aerodramus ceramensis), is a species of swift in the Apodidae family. It is endemic to Buru and Seram Islands. It used to be considered a subspecies of the Moluccan swiftlet. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical moist montane forests.','https://vignette.wikia.nocookie.net/animals/images/d/d3/Moluccanswift2.jpg/revision/latest?cb=20160826191222'), - ('Yap Monarch','Bird',499,'USD','The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.','https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519'), - ('Harpy Eagle','Bird',999,'USD','It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.','https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709'), - ('Speckled Piculet','Bird',1390,'USD','The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.','https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813'), - ('Congo Serpent Eagle','Bird',2990,'USD','The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests'' dark understories.','https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745'), - ('Bearded Bellbird','Bird',6990,'USD','This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).','https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300'), - ('Western Gorilla','Mammal',7290,'USD','The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.','https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304'), - ('Snow Leopard','Mammal',15490,'USD','The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.','https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225'), - ('Humpback Whale','Mammal',39990,'USD','The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.','https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349'), - ('Gray Wolf','Mammal',14990,'USD','The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They''re also highly territorial.','https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608'), - ('Moose','Mammal',27990,'USD','The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males; other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.','https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550'), - ('Brown Bear','Mammal',99990,'USD','The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it''s pet.','https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821'), - ('Tiger','Mammal',49990,'USD','The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.','https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111'), - ('Lion','Mammal',32790,'USD','The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.','https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314'), - ('Leopard','Mammal',26790,'USD','The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard''s rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar''s do. Both leopards and jaguars that are melanistic are known as black panthers.','https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105'), - ('Aardvark','Mammal',799,'USD','The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or ''thumb''), resulting in four toes, while the rear feet have all five toes.','https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128'), - ('Bison','Mammal',37490,'USD','The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American; Bison antiquus, B. latifrons, and B. occidentalis. The fourth; the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species; the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)','https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550'), - ('Cheetah','Mammal',24990,'USD','The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.','https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800'), - ('Inland Taipan','Reptile',1290,'USD','The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.','https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446'), - ('Green Sea Turtle','Reptile',499,'USD','The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.','https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939'), - ('Komodo Dragon','Reptile',7690,'USD','The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.','https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809'), - ('Egyptian Cobra','Reptile',2390,'USD','The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word naga meaning "cobra". The specific epithet haje is derived from the Arabic word hayya which literally means small "snake"-according to the Quran or "viper".','https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716'), - ('Round Island Burrowing Boa','Reptile',1790,'USD','The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.','https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644'), - ('Nile Crocodile','Reptile',14990,'USD','The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.','https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310'), - ('American Alligator','Reptile',17890,'USD','The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.','https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010'), - ('Black Mamba','Reptile',2290,'USD','The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.','https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636'), - ('Saltwater Crocodile','Reptile',31990,'USD','The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.','https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609'), - ('Panther chameleon','Reptile',1199,'USD','The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal''s feet. The specific name pardalisrefers to the animals'' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".','https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041'), - ('King Cobra','Reptile',1990,'USD','The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world''s longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.','https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332'), - ('Cape Melville Leaf-tailed Gecko','Reptile',99,'USD','The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard''s distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.','https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111'), - ('Axolotl','Amphibian',99,'USD','The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.','https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251'), - ('Cream-backed Poison Frog','Amphibian',49,'USD','The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males; this is the most notable difference between the sexes.','https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857'), - ('Tiger Salamander','Amphibian',79,'USD','The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.','https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118'), - ('Adelphobates galactonotus','Amphibian',129,'USD','Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.','https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901'), - ('Bale Mountains Tree Frog','Amphibian',169,'USD','The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.','https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022'), - ('Cape Rain Frog','Amphibian',99,'USD','The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft''s Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.','https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413'), - ('Desert Rain Frog','Amphibian',179,'USD','The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.','https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240'), - ('Excidobates captivus','Amphibian',239,'USD','Excidobates captivus, also known as the Santiago poison frog or Rio Santiago poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Peru and southern Ecuador. Its natural habitat is tropical moist lowland forests. This frog is black with rows of orange-red spots on its back and yellow spots underneath. With an adult snout-to-vent length of 15 to 17 mm (0.6 to 0.7 in), Excidobates captivus is a very small species of poison frog. It is black with orange-red splotches arranged in a row down either side of the back. It also has small yellow spots above the armpit and groin and further pale yellow spots beneath the chin and scattered on the chest and belly and under the thighs.','https://vignette.wikia.nocookie.net/animals/images/9/90/Captivus5.jpg/revision/latest?cb=20150627075858'), - ('Forest Rain Frog','Amphibian',29,'USD','The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.','https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517'), - ('Golden Poison Frog','Amphibian',399,'USD','The golden frog is found only in isolated regions of Panama. It''s bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.','https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049'), - ('Kihansi Spray Toad','Amphibian',149,'USD','The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.','https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143'), - ('Yellow-bellied Poison Frog','Amphibian',239,'USD','The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter; both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.','https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228'); + (DEFAULT,'Griffon Vulture','Bird',1990,'USD','The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.','https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933'), + (DEFAULT,'Bald Eagle','Bird',3490,'USD','The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aietos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.','https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710'), + (DEFAULT,'Osprey','Bird',1249,'USD','The osprey (Pandion haliaetus) - also called fish eagle, sea hawk, river hawk, and fish hawk - is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.','https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703'), + (DEFAULT,'Southern Cassowary','Bird',8990,'USD','The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.','https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613'), + (DEFAULT,'Wilson''s Bird-of-paradise','Bird',5499,'USD','The Wilson''s bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson''s bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson''s bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).','https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933'), + (DEFAULT,'Henderson Fruit Dove','Bird',12990,'USD','The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.','https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012'), + (DEFAULT,'Seram Swiftlet','Bird',799,'USD','The Seram swiftlet (Aerodramus ceramensis), is a species of swift in the Apodidae family. It is endemic to Buru and Seram Islands. It used to be considered a subspecies of the Moluccan swiftlet. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical moist montane forests.','https://vignette.wikia.nocookie.net/animals/images/d/d3/Moluccanswift2.jpg/revision/latest?cb=20160826191222'), + (DEFAULT,'Yap Monarch','Bird',499,'USD','The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.','https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519'), + (DEFAULT,'Harpy Eagle','Bird',999,'USD','It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.','https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709'), + (DEFAULT,'Speckled Piculet','Bird',1390,'USD','The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.','https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813'), + (DEFAULT,'Congo Serpent Eagle','Bird',2990,'USD','The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests'' dark understories.','https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745'), + (DEFAULT,'Bearded Bellbird','Bird',6990,'USD','This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).','https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300'), + (DEFAULT,'Western Gorilla','Mammal',7290,'USD','The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.','https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304'), + (DEFAULT,'Snow Leopard','Mammal',15490,'USD','The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.','https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225'), + (DEFAULT,'Humpback Whale','Mammal',39990,'USD','The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.','https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349'), + (DEFAULT,'Gray Wolf','Mammal',14990,'USD','The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They''re also highly territorial.','https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608'), + (DEFAULT,'Moose','Mammal',27990,'USD','The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males; other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.','https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550'), + (DEFAULT,'Brown Bear','Mammal',99990,'USD','The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it''s pet.','https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821'), + (DEFAULT,'Tiger','Mammal',49990,'USD','The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.','https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111'), + (DEFAULT,'Lion','Mammal',32790,'USD','The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.','https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314'), + (DEFAULT,'Leopard','Mammal',26790,'USD','The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard''s rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar''s do. Both leopards and jaguars that are melanistic are known as black panthers.','https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105'), + (DEFAULT,'Aardvark','Mammal',799,'USD','The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or ''thumb''), resulting in four toes, while the rear feet have all five toes.','https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128'), + (DEFAULT,'Bison','Mammal',37490,'USD','The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American; Bison antiquus, B. latifrons, and B. occidentalis. The fourth; the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species; the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)','https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550'), + (DEFAULT,'Cheetah','Mammal',24990,'USD','The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.','https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800'), + (DEFAULT,'Inland Taipan','Reptile',1290,'USD','The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.','https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446'), + (DEFAULT,'Green Sea Turtle','Reptile',499,'USD','The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.','https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939'), + (DEFAULT,'Komodo Dragon','Reptile',7690,'USD','The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.','https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809'), + (DEFAULT,'Egyptian Cobra','Reptile',2390,'USD','The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word naga meaning "cobra". The specific epithet haje is derived from the Arabic word hayya which literally means small "snake"-according to the Quran or "viper".','https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716'), + (DEFAULT,'Round Island Burrowing Boa','Reptile',1790,'USD','The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.','https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644'), + (DEFAULT,'Nile Crocodile','Reptile',14990,'USD','The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.','https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310'), + (DEFAULT,'American Alligator','Reptile',17890,'USD','The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.','https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010'), + (DEFAULT,'Black Mamba','Reptile',2290,'USD','The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.','https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636'), + (DEFAULT,'Saltwater Crocodile','Reptile',31990,'USD','The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.','https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609'), + (DEFAULT,'Panther chameleon','Reptile',1199,'USD','The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal''s feet. The specific name pardalisrefers to the animals'' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".','https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041'), + (DEFAULT,'King Cobra','Reptile',1990,'USD','The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world''s longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.','https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332'), + (DEFAULT,'Cape Melville Leaf-tailed Gecko','Reptile',99,'USD','The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard''s distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.','https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111'), + (DEFAULT,'Axolotl','Amphibian',99,'USD','The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.','https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251'), + (DEFAULT,'Cream-backed Poison Frog','Amphibian',49,'USD','The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males; this is the most notable difference between the sexes.','https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857'), + (DEFAULT,'Tiger Salamander','Amphibian',79,'USD','The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.','https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118'), + (DEFAULT,'Adelphobates galactonotus','Amphibian',129,'USD','Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.','https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901'), + (DEFAULT,'Bale Mountains Tree Frog','Amphibian',169,'USD','The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.','https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022'), + (DEFAULT,'Cape Rain Frog','Amphibian',99,'USD','The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft''s Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.','https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413'), + (DEFAULT,'Desert Rain Frog','Amphibian',179,'USD','The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.','https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240'), + (DEFAULT,'Excidobates captivus','Amphibian',239,'USD','Excidobates captivus, also known as the Santiago poison frog or Rio Santiago poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Peru and southern Ecuador. Its natural habitat is tropical moist lowland forests. This frog is black with rows of orange-red spots on its back and yellow spots underneath. With an adult snout-to-vent length of 15 to 17 mm (0.6 to 0.7 in), Excidobates captivus is a very small species of poison frog. It is black with orange-red splotches arranged in a row down either side of the back. It also has small yellow spots above the armpit and groin and further pale yellow spots beneath the chin and scattered on the chest and belly and under the thighs.','https://vignette.wikia.nocookie.net/animals/images/9/90/Captivus5.jpg/revision/latest?cb=20150627075858'), + (DEFAULT,'Forest Rain Frog','Amphibian',29,'USD','The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.','https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517'), + (DEFAULT,'Golden Poison Frog','Amphibian',399,'USD','The golden frog is found only in isolated regions of Panama. It''s bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.','https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049'), + (DEFAULT,'Kihansi Spray Toad','Amphibian',149,'USD','The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.','https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143'), + (DEFAULT,'Yellow-bellied Poison Frog','Amphibian',239,'USD','The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter; both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.','https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228'); diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index b239b3a..a108b79 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -4,9 +4,9 @@ import com.codecool.shop.dao.SpeciesDao; import com.codecool.shop.dao.AnimalDao; import com.codecool.shop.dao.ZooDao; -import com.codecool.shop.dao.implementation.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.AnimalDaoMem; -import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import com.codecool.shop.model.Animal; import com.codecool.shop.model.Order; import org.thymeleaf.TemplateEngine; diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index 9156699..6288b14 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -2,7 +2,7 @@ import com.codecool.shop.config.TemplateEngineUtil; import com.codecool.shop.dao.AnimalDao; -import com.codecool.shop.dao.implementation.AnimalDaoMem; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java new file mode 100644 index 0000000..4c23716 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java @@ -0,0 +1,46 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; +import com.codecool.shop.model.Zoo; + +import java.util.List; + +public class AnimalDaoDB implements AnimalDao { + + @Override + public void add(Animal product) { + + } + + @Override + public Animal find(int id) { + return null; + } + + @Override + public void remove(int id) { + + } + + @Override + public List getAll() { + return null; + } + + @Override + public List getBy(Zoo supplier) { + return null; + } + + @Override + public List getBy(Species productCategory) { + return null; + } + + @Override + public List getBy(Zoo supplier, Species productCategory) { + return null; + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/AnimalDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java similarity index 97% rename from src/main/java/com/codecool/shop/dao/implementation/AnimalDaoMem.java rename to src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java index aeffd1b..a768b6d 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/AnimalDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java @@ -1,4 +1,4 @@ -package com.codecool.shop.dao.implementation; +package com.codecool.shop.dao.implementation.Mem; import com.codecool.shop.dao.AnimalDao; diff --git a/src/main/java/com/codecool/shop/dao/implementation/SpeciesDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/SpeciesDaoMem.java similarity index 97% rename from src/main/java/com/codecool/shop/dao/implementation/SpeciesDaoMem.java rename to src/main/java/com/codecool/shop/dao/implementation/Mem/SpeciesDaoMem.java index 023a4d6..e48103a 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/SpeciesDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/SpeciesDaoMem.java @@ -1,4 +1,4 @@ -package com.codecool.shop.dao.implementation; +package com.codecool.shop.dao.implementation.Mem; import com.codecool.shop.dao.SpeciesDao; diff --git a/src/main/java/com/codecool/shop/dao/implementation/ZooDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/ZooDaoMem.java similarity index 95% rename from src/main/java/com/codecool/shop/dao/implementation/ZooDaoMem.java rename to src/main/java/com/codecool/shop/dao/implementation/Mem/ZooDaoMem.java index ef88b28..45487c4 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/ZooDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/ZooDaoMem.java @@ -1,7 +1,6 @@ -package com.codecool.shop.dao.implementation; +package com.codecool.shop.dao.implementation.Mem; import com.codecool.shop.dao.ZooDao; -import com.codecool.shop.model.Species; import com.codecool.shop.model.Zoo; import java.io.IOException; diff --git a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java index 31d12d7..87f130a 100644 --- a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java +++ b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java @@ -5,8 +5,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.sql.*; -import java.util.HashMap; -import java.util.Map; public class CodecoolShopDb { private static final String DEFAULT_PATH = System.getProperty("user.dir") + "/src/data"; @@ -56,6 +54,7 @@ public void executeUpdateFromFile(String filePath) { System.err.println("Bad filepath"); } catch (SQLException sqlError) { System.err.println("Sql problem"); + sqlError.printStackTrace(); } } @@ -76,7 +75,9 @@ public static void main(String[] args) throws SQLException { ResultSet birds = cdb.executeQuery("select * from animals where species='Bird'"); while(birds.next()) { - System.out.println(birds.getString(1)); + System.out.println(birds.getString("name")); } + cdb.executeUpdate("insert into animals values(default, 'name', 'Mammal', 4000, 'USD', 'desc', 'url')"); + cdb.executeUpdate("delete from animals where name = 'name' and description = 'desc'"); } } diff --git a/src/main/java/com/codecool/shop/model/Animal.java b/src/main/java/com/codecool/shop/model/Animal.java index c50ce21..7aec1a4 100644 --- a/src/main/java/com/codecool/shop/model/Animal.java +++ b/src/main/java/com/codecool/shop/model/Animal.java @@ -1,7 +1,7 @@ package com.codecool.shop.model; -import com.codecool.shop.dao.implementation.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import java.util.Currency; diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 044af34..5cef11f 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -3,9 +3,9 @@ import com.codecool.shop.dao.SpeciesDao; import com.codecool.shop.dao.AnimalDao; import com.codecool.shop.dao.ZooDao; -import com.codecool.shop.dao.implementation.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.AnimalDaoMem; -import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; From 05953168747475c5e2a16679d1ba3582cf482eb0 Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 30 May 2019 10:41:30 +0200 Subject: [PATCH 57/76] RegistrationController doGet method --- .../com/codecool/shop/controller/RegistrationController.java | 5 +++++ src/main/webapp/templates/cart/cart.html | 1 + src/main/webapp/templates/product/index.html | 1 + 3 files changed, 7 insertions(+) diff --git a/src/main/java/com/codecool/shop/controller/RegistrationController.java b/src/main/java/com/codecool/shop/controller/RegistrationController.java index a2b1e4b..b1c6328 100644 --- a/src/main/java/com/codecool/shop/controller/RegistrationController.java +++ b/src/main/java/com/codecool/shop/controller/RegistrationController.java @@ -22,4 +22,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se engine.process("registration/registration.html", context, resp.getWriter()); } + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + } + } diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index f2080b8..ca8e614 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -37,6 +37,7 @@

Cart

diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 8d36a07..4c32894 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -61,6 +61,7 @@

Codecool Shop

+ Sign up From c54fbfab1a25232312d235d09440b7d4540f05b3 Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 30 May 2019 11:43:15 +0200 Subject: [PATCH 58/76] UserDaoMem implemented --- .../controller/RegistrationController.java | 9 +++- .../java/com/codecool/shop/dao/UserDao.java | 11 +++++ .../shop/dao/implementation/UserDaoMem.java | 41 +++++++++++++++++ .../java/com/codecool/shop/model/User.java | 45 +++++++++++++++++++ .../templates/registration/registration.html | 3 +- 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/codecool/shop/dao/UserDao.java create mode 100644 src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java create mode 100644 src/main/java/com/codecool/shop/model/User.java diff --git a/src/main/java/com/codecool/shop/controller/RegistrationController.java b/src/main/java/com/codecool/shop/controller/RegistrationController.java index b1c6328..dc16ec8 100644 --- a/src/main/java/com/codecool/shop/controller/RegistrationController.java +++ b/src/main/java/com/codecool/shop/controller/RegistrationController.java @@ -1,10 +1,10 @@ package com.codecool.shop.controller; import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.model.User; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; -import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; @@ -24,6 +24,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String registrationName = req.getParameter("RegistrationName"); + String registrationEmail = req.getParameter("RegistrationEmail"); + String registrationPassword = req.getParameter("RegistrationPassword"); + + User user1 = new User(registrationName, registrationEmail, registrationPassword); + + resp.sendRedirect("/"); } diff --git a/src/main/java/com/codecool/shop/dao/UserDao.java b/src/main/java/com/codecool/shop/dao/UserDao.java new file mode 100644 index 0000000..2f40a39 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/UserDao.java @@ -0,0 +1,11 @@ +package com.codecool.shop.dao; + +import com.codecool.shop.model.User; + +public interface UserDao { + + void add(User user); + public User find(int id); + void remove(int id); + +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java new file mode 100644 index 0000000..1422f20 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java @@ -0,0 +1,41 @@ +package com.codecool.shop.dao.implementation; + +import com.codecool.shop.dao.UserDao; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.User; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +public class UserDaoMem implements UserDao { + + private List data = new ArrayList<>(); + private static UserDaoMem instance = null; + + /* A private Constructor prevents any other class from instantiating. + */ + private UserDaoMem() { + } + + public static UserDaoMem getInstance() { + if (instance == null) { + instance = new UserDaoMem(); + } + return instance; + } + + public void add(User user) { + data.add(user); + } + + public User find(int id) { + return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); + } + + public void remove(int id) { + data.remove(find(id)); + } + +} diff --git a/src/main/java/com/codecool/shop/model/User.java b/src/main/java/com/codecool/shop/model/User.java new file mode 100644 index 0000000..65d4272 --- /dev/null +++ b/src/main/java/com/codecool/shop/model/User.java @@ -0,0 +1,45 @@ +package com.codecool.shop.model; + +public class User { + + String name; + String email; + String password; + int id; + private static int idCounter; + + public User(String name, String email, String phone) { + this.name = name; + this.email = email; + this.password = phone; + this.id = idCounter++; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/main/webapp/templates/registration/registration.html b/src/main/webapp/templates/registration/registration.html index 530539b..5132aac 100644 --- a/src/main/webapp/templates/registration/registration.html +++ b/src/main/webapp/templates/registration/registration.html @@ -34,6 +34,7 @@

Registration

+
@@ -47,7 +48,7 @@

Registration

- +
From 0d6df214fcf5f12c96610bee01ad66e1722b4f0b Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 11:48:48 +0200 Subject: [PATCH 59/76] ProductDaoTest corrected according to the refactored names of other objects --- .../codecool/shop/tests/TestProductDao.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/codecool/shop/tests/TestProductDao.java b/src/main/java/com/codecool/shop/tests/TestProductDao.java index cd24f1f..daea11c 100644 --- a/src/main/java/com/codecool/shop/tests/TestProductDao.java +++ b/src/main/java/com/codecool/shop/tests/TestProductDao.java @@ -1,12 +1,12 @@ package com.codecool.shop.tests; -import com.codecool.shop.dao.ProductDao; -import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; -import com.codecool.shop.dao.implementation.ProductDaoMem; -import com.codecool.shop.dao.implementation.SupplierDaoMem; -import com.codecool.shop.model.Product; -import com.codecool.shop.model.ProductCategory; -import com.codecool.shop.model.Supplier; +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.implementation.AnimalDaoMem; +import com.codecool.shop.dao.implementation.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; +import com.codecool.shop.model.Zoo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,43 +16,43 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class TestProductDao { - private ProductDao productDao; + private AnimalDao animalDao; /** * Make a new instance every time before running a test */ @BeforeEach void setup() { - productDao = ProductDaoMem.getInstance(); + animalDao = AnimalDaoMem.getInstance(); } @Test void testGetBySupplier() { - Supplier supplier = SupplierDaoMem.getInstance().find(1); - List expected = new ArrayList<>(); - expected.add(productDao.find(12)); - expected.add(productDao.find(24)); - expected.add(productDao.find(36)); - expected.add(productDao.find(48)); - assertEquals(productDao.getBy(supplier), expected); + Zoo zoo = ZooDaoMem.getInstance().find(1); + List expected = new ArrayList<>(); + expected.add(animalDao.find(12)); + expected.add(animalDao.find(24)); + expected.add(animalDao.find(36)); + expected.add(animalDao.find(48)); + assertEquals(animalDao.getBy(zoo), expected); } @Test void testGetByProductCategory() { - ProductCategory productCategory = ProductCategoryDaoMem.getInstance().find(1); - List expected = new ArrayList<>(); - expected.add(productDao.find(1)); - expected.add(productDao.find(2)); - expected.add(productDao.find(3)); - expected.add(productDao.find(4)); - expected.add(productDao.find(5)); - expected.add(productDao.find(6)); - expected.add(productDao.find(7)); - expected.add(productDao.find(8)); - expected.add(productDao.find(9)); - expected.add(productDao.find(10)); - expected.add(productDao.find(11)); - expected.add(productDao.find(12)); - assertEquals(productDao.getBy(productCategory), expected); + Species productCategory = SpeciesDaoMem.getInstance().find(1); + List expected = new ArrayList<>(); + expected.add(animalDao.find(1)); + expected.add(animalDao.find(2)); + expected.add(animalDao.find(3)); + expected.add(animalDao.find(4)); + expected.add(animalDao.find(5)); + expected.add(animalDao.find(6)); + expected.add(animalDao.find(7)); + expected.add(animalDao.find(8)); + expected.add(animalDao.find(9)); + expected.add(animalDao.find(10)); + expected.add(animalDao.find(11)); + expected.add(animalDao.find(12)); + assertEquals(animalDao.getBy(productCategory), expected); } } From b2b31c6835aa8c510b478f0baeda9dd6570564fe Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 11:57:01 +0200 Subject: [PATCH 60/76] Test for find() method in AnimalDao --- src/main/java/com/codecool/shop/tests/TestProductDao.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/codecool/shop/tests/TestProductDao.java b/src/main/java/com/codecool/shop/tests/TestProductDao.java index daea11c..e79f6a4 100644 --- a/src/main/java/com/codecool/shop/tests/TestProductDao.java +++ b/src/main/java/com/codecool/shop/tests/TestProductDao.java @@ -26,6 +26,12 @@ void setup() { animalDao = AnimalDaoMem.getInstance(); } + @Test + void testFind() { + String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Alaska Zoo"; + assertEquals(expected, animalDao.find(1).toString()); + } + @Test void testGetBySupplier() { Zoo zoo = ZooDaoMem.getInstance().find(1); From 50ac9a099a3593424135ecd3214c5843bd0a4ff7 Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Thu, 30 May 2019 12:09:24 +0200 Subject: [PATCH 61/76] Database Database handlers done, not yet switched to it, need further testing. --- src/data/database/species.sql | 9 +- src/data/database/zoo.sql | 25 ++--- .../java/com/codecool/shop/dao/AnimalDao.java | 7 +- .../com/codecool/shop/dao/SpeciesDao.java | 2 +- .../java/com/codecool/shop/dao/ZooDao.java | 2 +- .../dao/implementation/DB/AnimalDaoDB.java | 82 +++++++++++++--- .../dao/implementation/DB/SpeciesDaoDB.java | 96 ++++++++++++++++++ .../shop/dao/implementation/DB/ZooDaoDB.java | 98 +++++++++++++++++++ .../dao/implementation/Mem/AnimalDaoMem.java | 15 --- ...odecoolShopDb.java => CodecoolShopDB.java} | 12 +-- .../java/com/codecool/shop/model/Animal.java | 15 ++- .../com/codecool/shop/model/BaseModel.java | 8 +- .../java/com/codecool/shop/model/Order.java | 54 ++++------ .../java/com/codecool/shop/model/Species.java | 7 ++ .../java/com/codecool/shop/model/Zoo.java | 15 +++ 15 files changed, 348 insertions(+), 99 deletions(-) create mode 100644 src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java create mode 100644 src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java rename src/main/java/com/codecool/shop/databaseHandler/{CodecoolShopDb.java => CodecoolShopDB.java} (90%) diff --git a/src/data/database/species.sql b/src/data/database/species.sql index a064c50..0aa0dc6 100644 --- a/src/data/database/species.sql +++ b/src/data/database/species.sql @@ -1,12 +1,13 @@ drop table if exists species cascade; CREATE TABLE "species" ( + "id" SERIAL NOT NULL UNIQUE, "name" TEXT primary key, "family" TEXT, "description" TEXT ); INSERT INTO "species" VALUES - ('Bird','Vertebrate','Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton.'), - ('Mammal','Vertebrate','Mammals (class Mammalia /məˈmeɪli.ə/ from Latin mamma "breast") are a clade of endothermic amniotes distinguished from reptiles and birds by the possession of a neocortex (a region of the brain), hair, three middle ear bones and mammary glands.'), - ('Reptile','Vertebrate','Reptiles are a group (Reptilia) of tetrapod animals comprising today''s turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives.'), - ('Amphibian','Vertebrate','The amphibians are tetrapods, a class of vertebrate animals with four limbs. They are non-amniotes, which means that their eggs are not surrounded by the several membranes, some impervious, which enable mammals, reptiles and birds to reproduce on land.'); + (DEFAULT,'Bird','Vertebrate','Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton.'), + (DEFAULT,'Mammal','Vertebrate','Mammals (class Mammalia /məˈmeɪli.ə/ from Latin mamma "breast") are a clade of endothermic amniotes distinguished from reptiles and birds by the possession of a neocortex (a region of the brain), hair, three middle ear bones and mammary glands.'), + (DEFAULT,'Reptile','Vertebrate','Reptiles are a group (Reptilia) of tetrapod animals comprising today''s turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives.'), + (DEFAULT,'Amphibian','Vertebrate','The amphibians are tetrapods, a class of vertebrate animals with four limbs. They are non-amniotes, which means that their eggs are not surrounded by the several membranes, some impervious, which enable mammals, reptiles and birds to reproduce on land.'); diff --git a/src/data/database/zoo.sql b/src/data/database/zoo.sql index 568ef82..f977a40 100644 --- a/src/data/database/zoo.sql +++ b/src/data/database/zoo.sql @@ -1,21 +1,22 @@ drop table if exists zoos; CREATE TABLE "zoos" ( + "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, "name" TEXT, "state" TEXT, "city" TEXT, "description" TEXT ); INSERT INTO "zoos" VALUES - ('Montgomery Zoo','Alabama','Montgomery','Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species.'), - ('Alaska Zoo','Alaska','Anchorage','The Alaska Zoo is a zoo in Anchorage, Alaska, located on 25 acres (10 ha) of the Anchorage Hillside. It is a popular attraction in Alaska, with nearly 200,000 visitors per year. The zoo is currently home to more than 100 birds and mammals representing some 50 species.'), - ('Phoenix Zoo','Arizona','Phoenix','The Phoenix Zoo opened in 1962 and is the largest privately owned, non-profit zoo in the United States. Located in Phoenix, Arizona, the zoo was founded by Robert Maytag, a member of the Maytag family, and operates on 125 acres (51 ha) of land in the Papago Park area of Phoenix. It has been designated as a Phoenix Point of Pride.'), - ('Los Angeles Zoo','California','Los Angeles','The Los Angeles Zoo and Botanical Gardens is a 133-acre (54 ha) zoo founded in 1966 and located in Los Angeles, California. The city of Los Angeles owns the entire zoo, its land and facilities, and the animals. Animal care, grounds maintenance, construction, education, public information, and administrative staff are city employees.'), - ('San Diego Zoo','California','San Diego','The San Diego Zoo is a zoo in Balboa Park, San Diego, California, housing more than 3,500 animals of more than 650 species and subspecies. Its parent organization, San Diego Zoo Global, is one of the largest[better source need zoological membership associations in the world, with more than 250,000 member households and 130,000 child memberships, representing more than a half million people.'), - ('San Francisco Zoo','California','San Francisco','The San Francisco Zoo is a 100-acre (40 ha) zoo located in the southwestern corner of San Francisco, California, between Lake Merced and the Pacific Ocean along the Great Highway. As of 2016, the zoo housed more than one thousand individual animals, representing more than 250 species. It is noted as the birthplace of Koko the gorilla, and, since 1974, the home of Elly, the oldest black rhinoceros in North America.'), - ('Disney''s Animal Kingdom','Florida','Bay Lake','Disney''s Animal Kingdom is a zoological theme park at the Walt Disney World Resort in Bay Lake, Florida, near Orlando. Owned and operated by The Walt Disney Company through its Parks, Experiences and Consumer Products division, it is the largest theme park in the world, covering 580 acres (230 ha). The park opened on Earth Day, April 22, 1998, and was the fourth theme park built at the resort.'), - ('Lion Country Safari','Florida','Loxahatchee','Lion Country Safari is a drive-through safari park and walk-through amusement park located on over 600 acres in Loxahatchee (near West Palm Beach), in Palm Beach County, Florida. Founded in 1967, it claims to be the first ''cageless zoo'' in the United States.'), - ('Monkey Jungle','Florida','Miami','Monkey Jungle is a 30-acre (12 ha) wildlife park established in 1933 for the exhibition and study of endangered monkeys in semi-natural habitats. Many projects have been conducted at the park, which is a tourist attraction in the Miami, Florida area. The park is in Redland, Florida at Southwest 216th Street/Hainlin Mill Road near Southwest 147th Avenue.'), - ('Reptile World Serpentarium','Florida','St. Cloud','Reptile World Serpentarium is a reptile zoo in St. Cloud, Osceola County, Florida. It features more than 75 species of snakes, as well as lizards, crocodiles, alligators, and turtles. It is operated by the herpetologist George Van Horn. In addition to having animals on display, it has venom milking shows.'), - ('World Center for Birds of Prey','Idaho','Boise','Built 35 years ago in 1984, the World Center for Birds of Prey is located on 580 acres (2.3 km2) on a hilltop overlooking Boise, south of the airport and east of Kuna. The campus consists of the business offices of The Peregrine Fund, breeding facilities for endangered raptors, the Velma Morrison Interpretive Center, and the Herrick Collections Building, which houses a large research library and the Archives of Falconry.'), - ('Yellowstone Bear World','Idaho','Rexburg','Yellowstone Bear World is a privately owned drive-thru wildlife park. It is located in Rexburg, Idaho, near Yellowstone National Park. It was established in 1998. The park holds over 8 species of wildlife indigenous to the Greater Yellowstone Ecosystem. Other attractions in the park include a small amusement park and a petting zoo. Yellowstone Bear World is the only wildlife park in the United States where guests can bottle feed bear cubs.'); + (DEFAULT,'Montgomery Zoo','Alabama','Montgomery','Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species.'), + (DEFAULT,'Alaska Zoo','Alaska','Anchorage','The Alaska Zoo is a zoo in Anchorage, Alaska, located on 25 acres (10 ha) of the Anchorage Hillside. It is a popular attraction in Alaska, with nearly 200,000 visitors per year. The zoo is currently home to more than 100 birds and mammals representing some 50 species.'), + (DEFAULT,'Phoenix Zoo','Arizona','Phoenix','The Phoenix Zoo opened in 1962 and is the largest privately owned, non-profit zoo in the United States. Located in Phoenix, Arizona, the zoo was founded by Robert Maytag, a member of the Maytag family, and operates on 125 acres (51 ha) of land in the Papago Park area of Phoenix. It has been designated as a Phoenix Point of Pride.'), + (DEFAULT,'Los Angeles Zoo','California','Los Angeles','The Los Angeles Zoo and Botanical Gardens is a 133-acre (54 ha) zoo founded in 1966 and located in Los Angeles, California. The city of Los Angeles owns the entire zoo, its land and facilities, and the animals. Animal care, grounds maintenance, construction, education, public information, and administrative staff are city employees.'), + (DEFAULT,'San Diego Zoo','California','San Diego','The San Diego Zoo is a zoo in Balboa Park, San Diego, California, housing more than 3,500 animals of more than 650 species and subspecies. Its parent organization, San Diego Zoo Global, is one of the largest[better source need zoological membership associations in the world, with more than 250,000 member households and 130,000 child memberships, representing more than a half million people.'), + (DEFAULT,'San Francisco Zoo','California','San Francisco','The San Francisco Zoo is a 100-acre (40 ha) zoo located in the southwestern corner of San Francisco, California, between Lake Merced and the Pacific Ocean along the Great Highway. As of 2016, the zoo housed more than one thousand individual animals, representing more than 250 species. It is noted as the birthplace of Koko the gorilla, and, since 1974, the home of Elly, the oldest black rhinoceros in North America.'), + (DEFAULT,'Disney''s Animal Kingdom','Florida','Bay Lake','Disney''s Animal Kingdom is a zoological theme park at the Walt Disney World Resort in Bay Lake, Florida, near Orlando. Owned and operated by The Walt Disney Company through its Parks, Experiences and Consumer Products division, it is the largest theme park in the world, covering 580 acres (230 ha). The park opened on Earth Day, April 22, 1998, and was the fourth theme park built at the resort.'), + (DEFAULT,'Lion Country Safari','Florida','Loxahatchee','Lion Country Safari is a drive-through safari park and walk-through amusement park located on over 600 acres in Loxahatchee (near West Palm Beach), in Palm Beach County, Florida. Founded in 1967, it claims to be the first ''cageless zoo'' in the United States.'), + (DEFAULT,'Monkey Jungle','Florida','Miami','Monkey Jungle is a 30-acre (12 ha) wildlife park established in 1933 for the exhibition and study of endangered monkeys in semi-natural habitats. Many projects have been conducted at the park, which is a tourist attraction in the Miami, Florida area. The park is in Redland, Florida at Southwest 216th Street/Hainlin Mill Road near Southwest 147th Avenue.'), + (DEFAULT,'Reptile World Serpentarium','Florida','St. Cloud','Reptile World Serpentarium is a reptile zoo in St. Cloud, Osceola County, Florida. It features more than 75 species of snakes, as well as lizards, crocodiles, alligators, and turtles. It is operated by the herpetologist George Van Horn. In addition to having animals on display, it has venom milking shows.'), + (DEFAULT,'World Center for Birds of Prey','Idaho','Boise','Built 35 years ago in 1984, the World Center for Birds of Prey is located on 580 acres (2.3 km2) on a hilltop overlooking Boise, south of the airport and east of Kuna. The campus consists of the business offices of The Peregrine Fund, breeding facilities for endangered raptors, the Velma Morrison Interpretive Center, and the Herrick Collections Building, which houses a large research library and the Archives of Falconry.'), + (DEFAULT,'Yellowstone Bear World','Idaho','Rexburg','Yellowstone Bear World is a privately owned drive-thru wildlife park. It is located in Rexburg, Idaho, near Yellowstone National Park. It was established in 1998. The park holds over 8 species of wildlife indigenous to the Greater Yellowstone Ecosystem. Other attractions in the park include a small amusement park and a petting zoo. Yellowstone Bear World is the only wildlife park in the United States where guests can bottle feed bear cubs.'); diff --git a/src/main/java/com/codecool/shop/dao/AnimalDao.java b/src/main/java/com/codecool/shop/dao/AnimalDao.java index f43f68b..6f5aa90 100644 --- a/src/main/java/com/codecool/shop/dao/AnimalDao.java +++ b/src/main/java/com/codecool/shop/dao/AnimalDao.java @@ -1,20 +1,15 @@ package com.codecool.shop.dao; -import com.codecool.shop.model.Zoo; import com.codecool.shop.model.Animal; -import com.codecool.shop.model.Species; import java.util.List; public interface AnimalDao { - void add(Animal product); + void add(Animal animal); Animal find(int id); void remove(int id); List getAll(); - List getBy(Zoo supplier); - List getBy(Species productCategory); - List getBy(Zoo supplier, Species productCategory); } diff --git a/src/main/java/com/codecool/shop/dao/SpeciesDao.java b/src/main/java/com/codecool/shop/dao/SpeciesDao.java index 56830c5..51c8f00 100644 --- a/src/main/java/com/codecool/shop/dao/SpeciesDao.java +++ b/src/main/java/com/codecool/shop/dao/SpeciesDao.java @@ -6,7 +6,7 @@ public interface SpeciesDao { - void add(Species category); + void add(Species species); Species find(int id); Species find(String name); diff --git a/src/main/java/com/codecool/shop/dao/ZooDao.java b/src/main/java/com/codecool/shop/dao/ZooDao.java index 5396106..30bb9ee 100644 --- a/src/main/java/com/codecool/shop/dao/ZooDao.java +++ b/src/main/java/com/codecool/shop/dao/ZooDao.java @@ -6,7 +6,7 @@ public interface ZooDao { - void add(Zoo supplier); + void add(Zoo zoo); Zoo find(int id); Zoo find(String name); void remove(int id); diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java index 4c23716..d116b51 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java @@ -1,46 +1,98 @@ package com.codecool.shop.dao.implementation.DB; import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; import com.codecool.shop.model.Animal; import com.codecool.shop.model.Species; -import com.codecool.shop.model.Zoo; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class AnimalDaoDB implements AnimalDao { - @Override - public void add(Animal product) { + private static AnimalDaoDB instance; + private CodecoolShopDB cdb; + private AnimalDaoDB() { + cdb = CodecoolShopDB.getInstance(); } - @Override - public Animal find(int id) { - return null; + public static AnimalDaoDB getInstance() { + if (instance == null) instance = new AnimalDaoDB(); + return instance; } @Override - public void remove(int id) { + public void add(Animal animal) { + try { + cdb.executeUpdate(String.format("INSERT INTO animals VALUES(default, '%1$s', '%2$s', %3$f, '%4$s', '%5$s', '%6$s')", + animal.getName(), + animal.getSpecies(), + animal.getDefaultPrice(), + animal.getDefaultCurrency(), + animal.getDescription(), + animal.getImgLink())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + public void add(String name, String speciesString, Double price, String currency, String description, String imgUrl) { + Species species = SpeciesDaoDB.getInstance().find(speciesString); + Animal animal = new Animal(name, species, price, currency, description, imgUrl); + add(animal); } @Override - public List getAll() { + public Animal find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM animals WHERE id = %1$d", id)); + if (result.next()) { + return getAnimalFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } return null; } @Override - public List getBy(Zoo supplier) { - return null; + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM animals WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } } @Override - public List getBy(Species productCategory) { - return null; + public List getAll() { + List animals = new ArrayList<>(); + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM animals"); + while(result.next()) { + animals.add(getAnimalFromResultSet(result)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return animals; } - @Override - public List getBy(Zoo supplier, Species productCategory) { - return null; + private Animal getAnimalFromResultSet(ResultSet result) throws SQLException { + Species species = SpeciesDaoDB.getInstance().find(result.getString("species")); + return new Animal( + result.getInt("id"), + result.getString("name"), + species, + result.getDouble("price"), + result.getString("currency"), + result.getString("description"), + result.getString("img_url")); } } diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java new file mode 100644 index 0000000..40149da --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java @@ -0,0 +1,96 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Species; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class SpeciesDaoDB implements SpeciesDao { + private static SpeciesDaoDB instance; + private CodecoolShopDB cdb; + + private SpeciesDaoDB() { + cdb = CodecoolShopDB.getInstance(); + } + + public static SpeciesDaoDB getInstance() { + if (instance == null) instance = new SpeciesDaoDB(); + return instance; + } + + @Override + public void add(Species species) { + try { + cdb.executeUpdate(String.format("INSERT INTO species VALUES(default, '%1$s', '%2$s', '%3$s')", + species.getName(), + species.getFamily(), + species.getDescription())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public Species find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM species WHERE id = %1$d", id)); + if (result.next()) { + return getSpeciesFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public Species find(String name) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM species WHERE name = '%1$s'", name)); + if (result.next()) { + return getSpeciesFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM species WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public List getAll() { + List species = new ArrayList<>(); + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM species"); + while(result.next()) { + species.add(getSpeciesFromResultSet(result)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return species; + } + + private Species getSpeciesFromResultSet(ResultSet result) throws SQLException { + return new Species( + result.getInt("id"), + result.getString("name"), + result.getString("family"), + result.getString("description")); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java new file mode 100644 index 0000000..c60aae7 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java @@ -0,0 +1,98 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Zoo; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class ZooDaoDB implements ZooDao { + private static ZooDaoDB instance = null; + private CodecoolShopDB cdb; + + private ZooDaoDB() { + cdb = CodecoolShopDB.getInstance(); + } + + public static ZooDaoDB getInstance() { + if (instance == null) instance = new ZooDaoDB(); + return instance; + } + + @Override + public void add(Zoo zoo) { + try { + cdb.executeUpdate(String.format("INSERT INTO zoos VALUES(default, '%1$s', '%2$s', '%3$s', '%4$s')", + zoo.getName(), + zoo.getState(), + zoo.getCity(), + zoo.getDescription())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public Zoo find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM zoos WHERE id = %1$d", id)); + if (result.next()) { + return getZooFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public Zoo find(String name) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM zoos WHERE name = '%1$s'", name)); + if (result.next()) { + return getZooFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM zoos WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public List getAll() { + List zoos = new ArrayList<>(); + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM zoos"); + while(result.next()) { + zoos.add(getZooFromResultSet(result)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return zoos; + } + + private Zoo getZooFromResultSet(ResultSet result) throws SQLException { + return new Zoo( + result.getInt("id"), + result.getString("name"), + result.getString("state"), + result.getString("city"), + result.getString("description")); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java index a768b6d..511a72f 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java @@ -58,19 +58,4 @@ public void remove(int id) { public List getAll() { return data; } - - @Override - public List getBy(Zoo zoo) { - return data.stream().filter(t -> t.getZoo().equals(zoo)).collect(Collectors.toList()); - } - - @Override - public List getBy(Species species) { - return data.stream().filter(t -> t.getSpecies().equals(species)).collect(Collectors.toList()); - } - - @Override - public List getBy(Zoo zoo, Species species) { - return data.stream().filter(t -> t.getZoo().equals(zoo) && t.getSpecies().equals(species)).collect(Collectors.toList()); - } } diff --git a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java similarity index 90% rename from src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java rename to src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java index 87f130a..55032d9 100644 --- a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDb.java +++ b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java @@ -6,22 +6,22 @@ import java.nio.file.Paths; import java.sql.*; -public class CodecoolShopDb { +public class CodecoolShopDB { private static final String DEFAULT_PATH = System.getProperty("user.dir") + "/src/data"; private static final String DATABASE = "jdbc:postgresql://localhost:5432/codecoolshop"; private static final String DB_USER = System.getenv("POSTGRES_DB_USER"); private static final String DB_PASSWORD = System.getenv("POSTGRES_DB_PASSWORD"); - private static CodecoolShopDb instance; + private static CodecoolShopDB instance; - private CodecoolShopDb() { + private CodecoolShopDB() { executeUpdateFromFile("/database/species.sql"); executeUpdateFromFile("/database/zoo.sql"); executeUpdateFromFile("/database/animal.sql"); } - public static CodecoolShopDb getInstance() { - if (instance == null) instance = new CodecoolShopDb(); + public static CodecoolShopDB getInstance() { + if (instance == null) instance = new CodecoolShopDB(); return instance; } @@ -71,7 +71,7 @@ public ResultSet executeQuery(String query) throws SQLException { } public static void main(String[] args) throws SQLException { - CodecoolShopDb cdb = CodecoolShopDb.getInstance(); + CodecoolShopDB cdb = CodecoolShopDB.getInstance(); ResultSet birds = cdb.executeQuery("select * from animals where species='Bird'"); while(birds.next()) { diff --git a/src/main/java/com/codecool/shop/model/Animal.java b/src/main/java/com/codecool/shop/model/Animal.java index 7aec1a4..91ed207 100644 --- a/src/main/java/com/codecool/shop/model/Animal.java +++ b/src/main/java/com/codecool/shop/model/Animal.java @@ -7,14 +7,14 @@ public class Animal extends BaseModel { - private float defaultPrice; + private double defaultPrice; private Currency defaultCurrency; private Species species; private Zoo zoo; private String imgLink; - public Animal(String name, Species species, float defaultPrice, String currencyString, String description, String imgLink) { + public Animal(String name, Species species, double defaultPrice, String currencyString, String description, String imgLink) { super(name, description); this.species = species; this.defaultPrice = defaultPrice; @@ -23,6 +23,15 @@ public Animal(String name, Species species, float defaultPrice, String currencyS zoo = ZooDaoMem.getInstance().next(); } + public Animal(int id, String name, Species species, double defaultPrice, String currencyString, String description, String imgLink) { + super(id, name, description); + this.species = species; + this.defaultPrice = defaultPrice; + this.defaultCurrency = Currency.getInstance(currencyString); + this.imgLink = imgLink; + zoo = ZooDaoMem.getInstance().next(); + } + public Animal(String[] data) { super(data[0], data[4]); species = SpeciesDaoMem.getInstance().find(data[1]); @@ -32,7 +41,7 @@ public Animal(String[] data) { zoo = ZooDaoMem.getInstance().next(); } - public float getDefaultPrice() { + public double getDefaultPrice() { return defaultPrice; } diff --git a/src/main/java/com/codecool/shop/model/BaseModel.java b/src/main/java/com/codecool/shop/model/BaseModel.java index d6e4fc1..ad0f5d0 100644 --- a/src/main/java/com/codecool/shop/model/BaseModel.java +++ b/src/main/java/com/codecool/shop/model/BaseModel.java @@ -3,7 +3,7 @@ import java.lang.reflect.Field; -public class BaseModel { +public abstract class BaseModel { protected int id; protected String name; @@ -18,6 +18,12 @@ public BaseModel(String name, String description) { this.description = description; } + public BaseModel(int id, String name, String description) { + this.id = id; + this.name = name; + this.description = description; + } + public int getId() { return id; diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 5cef11f..51e2ef4 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -1,11 +1,5 @@ package com.codecool.shop.model; -import com.codecool.shop.dao.SpeciesDao; -import com.codecool.shop.dao.AnimalDao; -import com.codecool.shop.dao.ZooDao; -import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; -import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; @@ -33,15 +27,15 @@ public class Order { private String zip; private int id; - private float priceSum; + private double priceSum; private int sumOfProducts; private boolean confirmed; private boolean paid; - private Map products; + private Map animals; private Order(){ this.id = ++instanceCounter; - products = new HashMap<>(); + animals = new HashMap<>(); } public static Order getInstance() { @@ -51,16 +45,16 @@ public static Order getInstance() { return instance; } - public void add(Animal product){ - products.merge(product, 1, Integer::sum); + public void add(Animal animal){ + animals.merge(animal, 1, Integer::sum); } - public void reduce(Animal product){ - if (products.get(product) != null) { - if(products.get(product) == 1){ - products.remove(product); + public void reduce(Animal animal){ + if (animals.get(animal) != null) { + if(animals.get(animal) == 1){ + animals.remove(animal); }else{ - products.put(product, products.get(product) - 1); + animals.put(animal, animals.get(animal) - 1); } } } @@ -69,17 +63,17 @@ public int getId() { return id; } - public float getPriceSum(){ + public double getPriceSum(){ priceSum = 0; - for (Map.Entry product : products.entrySet()){ - priceSum += product.getKey().getDefaultPrice() * product.getValue(); + for (Map.Entry animal : animals.entrySet()){ + priceSum += animal.getKey().getDefaultPrice() * animal.getValue(); } return priceSum; } public int getNumberOfProducts(){ sumOfProducts = 0; - for(int value : products.values()){ + for(int value : animals.values()){ sumOfProducts += value; } return sumOfProducts; @@ -94,14 +88,14 @@ public boolean isPaid() { } public Map getProductsOfOrder(){ - return products; + return animals; } - public float getSumOfPriceBy(Animal product) { - if (products.get(product) != null) { - return products.get(product) * product.getDefaultPrice(); + public double getSumOfPriceBy(Animal animal) { + if (animals.get(animal) != null) { + return animals.get(animal) * animal.getDefaultPrice(); } - return 0f; + return 0.0; } public void complete() { @@ -122,16 +116,6 @@ private void saveOrderToFile() { } } - public static void main(String[] args) { - AnimalDao productDataStore = AnimalDaoMem.getInstance(); - SpeciesDao productCategoryDataStore = SpeciesDaoMem.getInstance(); - ZooDao supplierDataStore = ZooDaoMem.getInstance(); - Order currentOrder = Order.getInstance(); - - productDataStore.getAll().forEach(currentOrder::add); - currentOrder.complete(); - } - public String getCustomerName() { return customerName; } diff --git a/src/main/java/com/codecool/shop/model/Species.java b/src/main/java/com/codecool/shop/model/Species.java index 2cb44d3..798cbf7 100644 --- a/src/main/java/com/codecool/shop/model/Species.java +++ b/src/main/java/com/codecool/shop/model/Species.java @@ -11,6 +11,13 @@ public Species(String name, String family, String description) { super(name); this.family = family; this.animals = new ArrayList<>(); + this.description = description; + } + + public Species(int id, String name, String family, String description) { + super(id, name, description); + this.family = family; + this.animals = new ArrayList<>(); } public Species(String[] data) { diff --git a/src/main/java/com/codecool/shop/model/Zoo.java b/src/main/java/com/codecool/shop/model/Zoo.java index 2e87a2d..520dcd2 100644 --- a/src/main/java/com/codecool/shop/model/Zoo.java +++ b/src/main/java/com/codecool/shop/model/Zoo.java @@ -15,6 +15,13 @@ public Zoo(String name, String state, String city, String description) { this.animals = new ArrayList<>(); } + public Zoo(int id, String name, String state, String city, String description) { + super(id, name, description); + this.state = state; + this.city = city; + this.animals = new ArrayList<>(); + } + public Zoo(String[] data) { super(data[0], data[3]); state = data[1]; @@ -43,4 +50,12 @@ public String toString() { this.description ); } + + public String getState() { + return state; + } + + public String getCity() { + return city; + } } \ No newline at end of file From b7364a084a6f28d9c73eb62791318c8d9cd999ad Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Thu, 30 May 2019 13:14:38 +0200 Subject: [PATCH 62/76] Database fully implemented Complete switch from csv to database --- .../shop/controller/ProductController.java | 20 ++++++++++---- .../controller/ShoppingCartController.java | 16 ++++++----- .../shop/dao/implementation/DB/ZooDaoDB.java | 27 +++++++++++++++++++ .../dao/implementation/Mem/AnimalDaoMem.java | 3 --- .../java/com/codecool/shop/model/Animal.java | 10 ++++--- .../java/com/codecool/shop/model/Order.java | 21 ++++++++++----- 6 files changed, 72 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index a108b79..9adb903 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -4,6 +4,9 @@ import com.codecool.shop.dao.SpeciesDao; import com.codecool.shop.dao.AnimalDao; import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; +import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; @@ -26,13 +29,17 @@ public class ProductController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - AnimalDao animalDataStore = AnimalDaoMem.getInstance(); - SpeciesDao speciesDataStore = SpeciesDaoMem.getInstance(); - ZooDao zooDataStore = ZooDaoMem.getInstance(); +// AnimalDao animalDataStore = AnimalDaoMem.getInstance(); +// SpeciesDao speciesDataStore = SpeciesDaoMem.getInstance(); +// ZooDao zooDataStore = ZooDaoMem.getInstance(); + + AnimalDao animalDataStore = AnimalDaoDB.getInstance(); + SpeciesDao speciesDataStore = SpeciesDaoDB.getInstance(); + ZooDao zooDataStore = ZooDaoDB.getInstance(); if (req.getParameter("id") != null){ int animalId = Integer.valueOf(req.getParameter("id")); - Order.getInstance().add(animalDataStore.find(animalId)); + Order.getInstance().add(animalId); } TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); @@ -53,7 +60,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S } private List filterAnimals(String species, String zoo) { - return AnimalDaoMem.getInstance().getAll().stream() +// AnimalDao datastore = AnimalDaoMem.getInstance(); + AnimalDao dataStore = AnimalDaoDB.getInstance(); + + return dataStore.getAll().stream() .filter(animal -> species == null || species.equals("") || animal.getSpecies().getId() == Integer.valueOf(species)) .filter(animal -> zoo == null || zoo.equals("") || animal.getZoo().getId() == Integer.valueOf(zoo)) .collect(Collectors.toList()); diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index 6288b14..0b59bd4 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -2,6 +2,7 @@ import com.codecool.shop.config.TemplateEngineUtil; import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -30,20 +31,21 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - AnimalDao productDataStore = AnimalDaoMem.getInstance(); +// AnimalDao animalDataStore = AnimalDaoMem.getInstance(); + AnimalDao animalDataStore = AnimalDaoDB.getInstance(); if (req.getParameter("id") != null) { - int productId = Integer.valueOf(req.getParameter("id")); - Order.getInstance().add(productDataStore.find(productId)); + int animalId = Integer.valueOf(req.getParameter("id")); + Order.getInstance().add(animalId); resp.sendRedirect("/"); } else if (req.getParameter("add-item-by-id") != null){ - int productId = Integer.valueOf(req.getParameter("add-item-by-id")); - Order.getInstance().add(productDataStore.find(productId)); + int animalId = Integer.valueOf(req.getParameter("add-item-by-id")); + Order.getInstance().add(animalId); doGet(req, resp); } else if (req.getParameter("reduce-item-by-id") != null){ - int productId = Integer.valueOf(req.getParameter("reduce-item-by-id")); - Order.getInstance().reduce(productDataStore.find(productId)); + int animalId = Integer.valueOf(req.getParameter("reduce-item-by-id")); + Order.getInstance().reduce(animalId); doGet(req, resp); } diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java index c60aae7..2586a10 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java @@ -12,9 +12,19 @@ public class ZooDaoDB implements ZooDao { private static ZooDaoDB instance = null; private CodecoolShopDB cdb; + private int current; + private int numOfZoos; private ZooDaoDB() { cdb = CodecoolShopDB.getInstance(); + try { + ResultSet result = cdb.executeQuery("SELECT COUNT(*) FROM zoos"); + if (result.next()) { + numOfZoos = result.getInt(1); + } + } catch (SQLException e) { + e.printStackTrace(); + } } public static ZooDaoDB getInstance() { @@ -30,6 +40,7 @@ public void add(Zoo zoo) { zoo.getState(), zoo.getCity(), zoo.getDescription())); + numOfZoos++; } catch (SQLException e) { e.printStackTrace(); } @@ -67,6 +78,7 @@ public Zoo find(String name) { public void remove(int id) { try { cdb.executeUpdate(String.format("DELETE FROM zoos WHERE id = %1$d", id)); + numOfZoos--; } catch (SQLException e) { e.printStackTrace(); } @@ -95,4 +107,19 @@ private Zoo getZooFromResultSet(ResultSet result) throws SQLException { result.getString("city"), result.getString("description")); } + + public Zoo next() { + current = (current % numOfZoos) + 1; + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM zoos"); + for (int i = 0; i < current; i++) { + result.next(); + } + return getZooFromResultSet(result); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } } diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java index 511a72f..3d1ce33 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java @@ -3,8 +3,6 @@ import com.codecool.shop.dao.AnimalDao; import com.codecool.shop.model.Animal; -import com.codecool.shop.model.Species; -import com.codecool.shop.model.Zoo; import java.io.IOException; import java.nio.file.Files; @@ -12,7 +10,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class AnimalDaoMem implements AnimalDao { private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/csv/animals.csv"); diff --git a/src/main/java/com/codecool/shop/model/Animal.java b/src/main/java/com/codecool/shop/model/Animal.java index 91ed207..254af95 100644 --- a/src/main/java/com/codecool/shop/model/Animal.java +++ b/src/main/java/com/codecool/shop/model/Animal.java @@ -1,5 +1,6 @@ package com.codecool.shop.model; +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; @@ -20,7 +21,8 @@ public Animal(String name, Species species, double defaultPrice, String currency this.defaultPrice = defaultPrice; this.defaultCurrency = Currency.getInstance(currencyString); this.imgLink = imgLink; - zoo = ZooDaoMem.getInstance().next(); +// zoo = ZooDaoMem.getInstance().next(); + zoo = ZooDaoDB.getInstance().next(); } public Animal(int id, String name, Species species, double defaultPrice, String currencyString, String description, String imgLink) { @@ -29,7 +31,8 @@ public Animal(int id, String name, Species species, double defaultPrice, String this.defaultPrice = defaultPrice; this.defaultCurrency = Currency.getInstance(currencyString); this.imgLink = imgLink; - zoo = ZooDaoMem.getInstance().next(); +// zoo = ZooDaoMem.getInstance().next(); + zoo = ZooDaoDB.getInstance().next(); } public Animal(String[] data) { @@ -38,7 +41,8 @@ public Animal(String[] data) { defaultPrice = Integer.valueOf(data[2]); defaultCurrency = Currency.getInstance(data[3]); imgLink = data[5]; - zoo = ZooDaoMem.getInstance().next(); +// zoo = ZooDaoMem.getInstance().next(); + zoo = ZooDaoDB.getInstance().next(); } public double getDefaultPrice() { diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java index 51e2ef4..debb192 100644 --- a/src/main/java/com/codecool/shop/model/Order.java +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -1,5 +1,6 @@ package com.codecool.shop.model; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; @@ -45,16 +46,22 @@ public static Order getInstance() { return instance; } - public void add(Animal animal){ - animals.merge(animal, 1, Integer::sum); + public void add(int animalId){ + Animal existingAnimal = animals.keySet().stream().filter(anim -> anim.getId() == animalId) + .findFirst().orElse(null); + if (existingAnimal == null) animals.put(AnimalDaoDB.getInstance().find(animalId), 1); + else animals.merge(existingAnimal, 1, Integer::sum); } - public void reduce(Animal animal){ - if (animals.get(animal) != null) { - if(animals.get(animal) == 1){ - animals.remove(animal); + public void reduce(int animalId){ + Animal existingAnimal = animals.keySet().stream().filter(anim -> anim.getId() == animalId) + .findFirst().orElse(null); + + if (animals.get(existingAnimal) != null) { + if(animals.get(existingAnimal) == 1){ + animals.remove(existingAnimal); }else{ - animals.put(animal, animals.get(animal) - 1); + animals.put(existingAnimal, animals.get(existingAnimal) - 1); } } } From a2f5893e9b7005bc890ed3289879c6d27665d516 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 13:19:46 +0200 Subject: [PATCH 63/76] Refactoring test name and testing getAll() --- .../shop/tests/{TestProductDao.java => TestAnimalDao.java} | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename src/main/java/com/codecool/shop/tests/{TestProductDao.java => TestAnimalDao.java} (94%) diff --git a/src/main/java/com/codecool/shop/tests/TestProductDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java similarity index 94% rename from src/main/java/com/codecool/shop/tests/TestProductDao.java rename to src/main/java/com/codecool/shop/tests/TestAnimalDao.java index e79f6a4..663463c 100644 --- a/src/main/java/com/codecool/shop/tests/TestProductDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class TestProductDao { +public class TestAnimalDao { private AnimalDao animalDao; /** @@ -61,4 +61,9 @@ void testGetByProductCategory() { expected.add(animalDao.find(12)); assertEquals(animalDao.getBy(productCategory), expected); } + + @Test + void testGetAll() { + assertEquals(48, animalDao.getAll().size()); + } } From a8b55b9f3b9c1ca2f9275d82d6db24eb42878fc8 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 13:27:01 +0200 Subject: [PATCH 64/76] Tests for SpeciesDao and ZooDao --- .../codecool/shop/tests/TestSpeciesDao.java | 45 +++++++++++++++++++ .../com/codecool/shop/tests/TestZooDao.java | 45 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/main/java/com/codecool/shop/tests/TestSpeciesDao.java create mode 100644 src/main/java/com/codecool/shop/tests/TestZooDao.java diff --git a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java new file mode 100644 index 0000000..9f15e84 --- /dev/null +++ b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java @@ -0,0 +1,45 @@ +package com.codecool.shop.tests; + +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.dao.implementation.SpeciesDaoMem; +import com.codecool.shop.model.Species; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestSpeciesDao { + private SpeciesDao speciesDao; + + /** + * Make a new instance every time before running a test + */ + @BeforeEach + void setup() { + speciesDao = SpeciesDaoMem.getInstance(); + } + + @Test + void testAdd() { + Species newSpecies = new Species("Sample", "Sample", "Sample"); + speciesDao.add(newSpecies); + assert(speciesDao.getAll().contains(newSpecies)); + } + + @Test + void testFindById() { + String expected = "id: 1,name: Bird, family: Vertebrate, description: Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; + assertEquals(expected, speciesDao.find(1).toString()); + } + + @Test + void testFindByName() { + String expected = "id: 1,name: Bird, family: Vertebrate, description: Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; + assertEquals(expected, speciesDao.find("Bird").toString()); + } + + @Test + void testGetAll() { + assertEquals(5, speciesDao.getAll().size()); + } +} diff --git a/src/main/java/com/codecool/shop/tests/TestZooDao.java b/src/main/java/com/codecool/shop/tests/TestZooDao.java new file mode 100644 index 0000000..fd36b09 --- /dev/null +++ b/src/main/java/com/codecool/shop/tests/TestZooDao.java @@ -0,0 +1,45 @@ +package com.codecool.shop.tests; + +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.model.Zoo; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestZooDao { + private ZooDao zooDao; + + /** + * Make a new instance every time before running a test + */ + @BeforeEach + void setup() { + zooDao = ZooDaoMem.getInstance(); + } + + @Test + void testAdd() { + Zoo newZoo = new Zoo("Sample", "Sample", "Sample", "Sample"); + zooDao.add(newZoo); + assert(zooDao.getAll().contains(newZoo)); + } + + @Test + void testFindById() { + String expected = "id: 1, name: Montgomery Zoo, description: Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species."; + assertEquals(expected, zooDao.find(1).toString()); + } + + @Test + void testFindByName() { + String expected = "id: 1, name: Montgomery Zoo, description: Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species."; + assertEquals(expected, zooDao.find("Montgomery Zoo").toString()); + } + + @Test + void testGetAll() { + assertEquals(13, zooDao.getAll().size()); + } +} From 1465db67b63b881df0d6c1f0a3f830f3a7fe4f6d Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 30 May 2019 13:32:01 +0200 Subject: [PATCH 65/76] users table --- src/main/webapp/templates/cart/cart.html | 4 +++- src/main/webapp/templates/product/index.html | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html index 0c187c5..cde6d59 100644 --- a/src/main/webapp/templates/cart/cart.html +++ b/src/main/webapp/templates/cart/cart.html @@ -37,7 +37,9 @@

Cart

- Sign up +
+ Sign up +
diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index 5476cdf..172426d 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -33,6 +33,7 @@

Codecool Shop

+
@@ -56,12 +57,13 @@

Codecool Shop

-
-
- Sign up + +
+ Sign up +
From 979baa88c2dedbc993ff36fbcd22b1ee5e80bbae Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 13:51:35 +0200 Subject: [PATCH 66/76] alter tests after merge to avoid exceptions --- .../codecool/shop/tests/TestAnimalDao.java | 84 +++++++++---------- .../codecool/shop/tests/TestSpeciesDao.java | 2 +- .../com/codecool/shop/tests/TestZooDao.java | 2 +- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java index 663463c..da5f9cb 100644 --- a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -1,9 +1,9 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.AnimalDao; -import com.codecool.shop.dao.implementation.AnimalDaoMem; -import com.codecool.shop.dao.implementation.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import com.codecool.shop.model.Animal; import com.codecool.shop.model.Species; import com.codecool.shop.model.Zoo; @@ -26,44 +26,44 @@ void setup() { animalDao = AnimalDaoMem.getInstance(); } - @Test - void testFind() { - String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Alaska Zoo"; - assertEquals(expected, animalDao.find(1).toString()); - } - - @Test - void testGetBySupplier() { - Zoo zoo = ZooDaoMem.getInstance().find(1); - List expected = new ArrayList<>(); - expected.add(animalDao.find(12)); - expected.add(animalDao.find(24)); - expected.add(animalDao.find(36)); - expected.add(animalDao.find(48)); - assertEquals(animalDao.getBy(zoo), expected); - } +// @Test +// void testFind() { +// String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Alaska Zoo"; +// assertEquals(expected, animalDao.find(1).toString()); +// } - @Test - void testGetByProductCategory() { - Species productCategory = SpeciesDaoMem.getInstance().find(1); - List expected = new ArrayList<>(); - expected.add(animalDao.find(1)); - expected.add(animalDao.find(2)); - expected.add(animalDao.find(3)); - expected.add(animalDao.find(4)); - expected.add(animalDao.find(5)); - expected.add(animalDao.find(6)); - expected.add(animalDao.find(7)); - expected.add(animalDao.find(8)); - expected.add(animalDao.find(9)); - expected.add(animalDao.find(10)); - expected.add(animalDao.find(11)); - expected.add(animalDao.find(12)); - assertEquals(animalDao.getBy(productCategory), expected); - } - - @Test - void testGetAll() { - assertEquals(48, animalDao.getAll().size()); - } +// @Test +// void testGetBySupplier() { +// Zoo zoo = ZooDaoMem.getInstance().find(1); +// List expected = new ArrayList<>(); +// expected.add(animalDao.find(12)); +// expected.add(animalDao.find(24)); +// expected.add(animalDao.find(36)); +// expected.add(animalDao.find(48)); +// assertEquals(animalDao.getBy(zoo), expected); +// } +// +// @Test +// void testGetByProductCategory() { +// Species productCategory = SpeciesDaoMem.getInstance().find(1); +// List expected = new ArrayList<>(); +// expected.add(animalDao.find(1)); +// expected.add(animalDao.find(2)); +// expected.add(animalDao.find(3)); +// expected.add(animalDao.find(4)); +// expected.add(animalDao.find(5)); +// expected.add(animalDao.find(6)); +// expected.add(animalDao.find(7)); +// expected.add(animalDao.find(8)); +// expected.add(animalDao.find(9)); +// expected.add(animalDao.find(10)); +// expected.add(animalDao.find(11)); +// expected.add(animalDao.find(12)); +// assertEquals(animalDao.getBy(productCategory), expected); +// } +// +// @Test +// void testGetAll() { +// assertEquals(48, animalDao.getAll().size()); +// } } diff --git a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java index 9f15e84..33e7ba3 100644 --- a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java +++ b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java @@ -1,7 +1,7 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.SpeciesDao; -import com.codecool.shop.dao.implementation.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; import com.codecool.shop.model.Species; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/main/java/com/codecool/shop/tests/TestZooDao.java b/src/main/java/com/codecool/shop/tests/TestZooDao.java index fd36b09..64002b0 100644 --- a/src/main/java/com/codecool/shop/tests/TestZooDao.java +++ b/src/main/java/com/codecool/shop/tests/TestZooDao.java @@ -1,7 +1,7 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.ZooDao; -import com.codecool.shop.dao.implementation.ZooDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import com.codecool.shop.model.Zoo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From 168c241c26f00cdb31d70e9e487dcef5d661ecab Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 30 May 2019 13:56:41 +0200 Subject: [PATCH 67/76] users sql --- src/data/database/users.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/data/database/users.sql diff --git a/src/data/database/users.sql b/src/data/database/users.sql new file mode 100644 index 0000000..f0fc4d0 --- /dev/null +++ b/src/data/database/users.sql @@ -0,0 +1,8 @@ +drop table if exists users; + +CREATE TABLE "users" ( + "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, + "name" VARCHAR(255), + "email" VARCHAR(255), + "password" VARCHAR(255), +); \ No newline at end of file From fa71ca913c9651725257ccd1063a86fdbbba84ec Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 14:34:08 +0200 Subject: [PATCH 68/76] uncomment some tests, parameterized junit test added to pom.xml --- pom.xml | 12 +++++++++++ .../codecool/shop/tests/TestAnimalDao.java | 21 ++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 878f3e1..5acd56e 100644 --- a/pom.xml +++ b/pom.xml @@ -81,5 +81,17 @@ 5.3.2 compile + + org.junit.jupiter + junit-jupiter-params + 5.1.0 + test + + + org.junit.jupiter + junit-jupiter-params + 5.3.2 + compile + \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java index da5f9cb..cec19a7 100644 --- a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -1,6 +1,7 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; @@ -26,11 +27,11 @@ void setup() { animalDao = AnimalDaoMem.getInstance(); } -// @Test -// void testFind() { -// String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Alaska Zoo"; -// assertEquals(expected, animalDao.find(1).toString()); -// } + @Test + void testFind() { + String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Montgomery Zoo"; + assertEquals(expected, animalDao.find(1).toString()); + } // @Test // void testGetBySupplier() { @@ -61,9 +62,9 @@ void setup() { // expected.add(animalDao.find(12)); // assertEquals(animalDao.getBy(productCategory), expected); // } -// -// @Test -// void testGetAll() { -// assertEquals(48, animalDao.getAll().size()); -// } + + @Test + void testGetAll() { + assertEquals(48, animalDao.getAll().size()); + } } From 94bf89ec21613c82fb6f4c32bc09c332482f54e5 Mon Sep 17 00:00:00 2001 From: Erika Toth Date: Thu, 30 May 2019 14:57:12 +0200 Subject: [PATCH 69/76] RegistrationController add user method --- src/data/database/users.sql | 2 +- .../controller/RegistrationController.java | 7 +- .../shop/dao/implementation/DB/UserDaoDB.java | 78 +++++++++++++++++++ .../implementation/{ => Mem}/UserDaoMem.java | 5 +- .../shop/databaseHandler/CodecoolShopDB.java | 1 + 5 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java rename src/main/java/com/codecool/shop/dao/implementation/{ => Mem}/UserDaoMem.java (85%) diff --git a/src/data/database/users.sql b/src/data/database/users.sql index f0fc4d0..c1e930e 100644 --- a/src/data/database/users.sql +++ b/src/data/database/users.sql @@ -4,5 +4,5 @@ CREATE TABLE "users" ( "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, "name" VARCHAR(255), "email" VARCHAR(255), - "password" VARCHAR(255), + "password" VARCHAR(255) ); \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/controller/RegistrationController.java b/src/main/java/com/codecool/shop/controller/RegistrationController.java index dc16ec8..201277a 100644 --- a/src/main/java/com/codecool/shop/controller/RegistrationController.java +++ b/src/main/java/com/codecool/shop/controller/RegistrationController.java @@ -1,6 +1,8 @@ package com.codecool.shop.controller; import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.dao.UserDao; +import com.codecool.shop.dao.implementation.DB.UserDaoDB; import com.codecool.shop.model.User; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -28,7 +30,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S String registrationEmail = req.getParameter("RegistrationEmail"); String registrationPassword = req.getParameter("RegistrationPassword"); - User user1 = new User(registrationName, registrationEmail, registrationPassword); + User user = new User(registrationName, registrationEmail, registrationPassword); + + UserDao userDao = UserDaoDB.getInstance(); + userDao.add(user); resp.sendRedirect("/"); diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java new file mode 100644 index 0000000..0bbce07 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java @@ -0,0 +1,78 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.UserDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; +import com.codecool.shop.model.User; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + + +public class UserDaoDB implements UserDao { + + private static UserDaoDB instance; + private CodecoolShopDB cdb; + + private UserDaoDB() { + cdb = CodecoolShopDB.getInstance(); + } + + public static UserDaoDB getInstance() { + if (instance == null) instance = new UserDaoDB(); + return instance; + } + + + @Override + public void add(User user) { + try { + cdb.executeUpdate(String.format("INSERT INTO users VALUES(default, '%1$s', '%2$s', '%3$s')", + user.getName(), + user.getEmail(), + user.getPassword())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void add(String name, String email, String password) { + User user = new User(name, email, password); + add(user); + } + + @Override + public User find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM users WHERE id = %1$d", id)); + if (result.next()) { + return getUserFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM users WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private User getUserFromResultSet(ResultSet result) throws SQLException { + return new User( + result.getString("name"), + result.getString("email"), + result.getString("password")); + } + +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/UserDaoMem.java similarity index 85% rename from src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java rename to src/main/java/com/codecool/shop/dao/implementation/Mem/UserDaoMem.java index 1422f20..b03988e 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/UserDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/UserDaoMem.java @@ -1,11 +1,8 @@ -package com.codecool.shop.dao.implementation; +package com.codecool.shop.dao.implementation.Mem; import com.codecool.shop.dao.UserDao; -import com.codecool.shop.model.Animal; import com.codecool.shop.model.User; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java index 55032d9..e1aa079 100644 --- a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java +++ b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java @@ -18,6 +18,7 @@ private CodecoolShopDB() { executeUpdateFromFile("/database/species.sql"); executeUpdateFromFile("/database/zoo.sql"); executeUpdateFromFile("/database/animal.sql"); + executeUpdateFromFile("/database/users.sql"); } public static CodecoolShopDB getInstance() { From 78e96ea264af1c21285238c30649282d50d1173b Mon Sep 17 00:00:00 2001 From: Benjamin Kovacs Date: Thu, 30 May 2019 16:02:36 +0200 Subject: [PATCH 70/76] Added config file -> easy to switch between DB and Mem Created MainDao.java class that handles what is in the config file and stores the required singletons --- config | 1 + .../shop/controller/ProductController.java | 26 ++---- .../controller/ShoppingCartController.java | 7 -- .../dao/implementation/DB/AnimalDaoDB.java | 4 +- .../shop/dao/implementation/Main/MainDao.java | 81 +++++++++++++++++++ .../dao/implementation/Mem/AnimalDaoMem.java | 6 +- .../shop/databaseHandler/CodecoolShopDB.java | 11 --- .../java/com/codecool/shop/model/Animal.java | 1 - 8 files changed, 95 insertions(+), 42 deletions(-) create mode 100644 config create mode 100644 src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java diff --git a/config b/config new file mode 100644 index 0000000..79fe122 --- /dev/null +++ b/config @@ -0,0 +1 @@ +datasource=DB \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 9adb903..75a8a97 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -4,12 +4,7 @@ import com.codecool.shop.dao.SpeciesDao; import com.codecool.shop.dao.AnimalDao; import com.codecool.shop.dao.ZooDao; -import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; -import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; -import com.codecool.shop.dao.implementation.DB.ZooDaoDB; -import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; -import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; +import com.codecool.shop.dao.implementation.Main.MainDao; import com.codecool.shop.model.Animal; import com.codecool.shop.model.Order; import org.thymeleaf.TemplateEngine; @@ -29,13 +24,9 @@ public class ProductController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { -// AnimalDao animalDataStore = AnimalDaoMem.getInstance(); -// SpeciesDao speciesDataStore = SpeciesDaoMem.getInstance(); -// ZooDao zooDataStore = ZooDaoMem.getInstance(); - - AnimalDao animalDataStore = AnimalDaoDB.getInstance(); - SpeciesDao speciesDataStore = SpeciesDaoDB.getInstance(); - ZooDao zooDataStore = ZooDaoDB.getInstance(); + AnimalDao animalDataStore = MainDao.getAnimalDaoInstance(); + SpeciesDao speciesDataStore = MainDao.getSpeciesDaoInstance(); + ZooDao zooDataStore = MainDao.getZooDaoInstance(); if (req.getParameter("id") != null){ int animalId = Integer.valueOf(req.getParameter("id")); @@ -51,7 +42,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se context.setVariable("species", speciesDataStore.getAll()); context.setVariable("zoos", zooDataStore.getAll()); context.setVariable("cart", Order.getInstance()); - context.setVariable("animals", filterAnimals(filter_species, filter_zoo)); + context.setVariable("animals", filterAnimals(filter_species, filter_zoo, animalDataStore)); engine.process("product/index.html", context, resp.getWriter()); } @@ -59,11 +50,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S doGet(req, resp); } - private List filterAnimals(String species, String zoo) { -// AnimalDao datastore = AnimalDaoMem.getInstance(); - AnimalDao dataStore = AnimalDaoDB.getInstance(); - - return dataStore.getAll().stream() + private List filterAnimals(String species, String zoo, AnimalDao animalDataStore) { + return animalDataStore.getAll().stream() .filter(animal -> species == null || species.equals("") || animal.getSpecies().getId() == Integer.valueOf(species)) .filter(animal -> zoo == null || zoo.equals("") || animal.getZoo().getId() == Integer.valueOf(zoo)) .collect(Collectors.toList()); diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java index 0b59bd4..cc83f8b 100644 --- a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -1,9 +1,6 @@ package com.codecool.shop.controller; import com.codecool.shop.config.TemplateEngineUtil; -import com.codecool.shop.dao.AnimalDao; -import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; -import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -30,10 +27,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - -// AnimalDao animalDataStore = AnimalDaoMem.getInstance(); - AnimalDao animalDataStore = AnimalDaoDB.getInstance(); - if (req.getParameter("id") != null) { int animalId = Integer.valueOf(req.getParameter("id")); Order.getInstance().add(animalId); diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java index d116b51..1c44cfd 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java @@ -49,7 +49,9 @@ public void add(String name, String speciesString, Double price, String currency public Animal find(int id) { ResultSet result; try { - result = cdb.executeQuery(String.format("SELECT * FROM animals WHERE id = %1$d", id)); + result = cdb.executeQuery(String.format( + "SELECT * FROM animals WHERE id = %1$d", id) + ); if (result.next()) { return getAnimalFromResultSet(result); } diff --git a/src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java b/src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java new file mode 100644 index 0000000..6479f04 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java @@ -0,0 +1,81 @@ +package com.codecool.shop.dao.implementation.Main; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; +import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +public class MainDao { + private static final Path PATH_TO_CONFIG = Paths.get( + System.getProperty("user.dir"), "/config"); + + private static AnimalDao animalDaoInstance; + private static SpeciesDao speciesDaoInstance; + private static ZooDao zooDaoInstance; + + private static String dataSource = getDataSource(); + + public static AnimalDao getAnimalDaoInstance() { + if (animalDaoInstance == null) { + if (dataSource.equals("DB")) { + animalDaoInstance = AnimalDaoDB.getInstance(); + System.out.println("Using DataBase"); + } else { + animalDaoInstance = AnimalDaoMem.getInstance(); + System.out.println("Using Memory"); + } + } + return animalDaoInstance; + } + + public static SpeciesDao getSpeciesDaoInstance() { + if (speciesDaoInstance == null) { + if (dataSource.equals("DB")) { + speciesDaoInstance = SpeciesDaoDB.getInstance(); + System.out.println("Using DataBase"); + } else { + speciesDaoInstance = SpeciesDaoMem.getInstance(); + System.out.println("Using Memory"); + } + } + return speciesDaoInstance; + } + + public static ZooDao getZooDaoInstance() { + if (zooDaoInstance == null) { + if (dataSource.equals("DB")) { + zooDaoInstance = ZooDaoDB.getInstance(); + System.out.println("Using DataBase"); + } else { + zooDaoInstance = ZooDaoMem.getInstance(); + System.out.println("Using Memory"); + } + } + return zooDaoInstance; + } + + private static Properties getProperties() { + Properties properties = new Properties(); + try { + properties.load(Files.newBufferedReader(PATH_TO_CONFIG)); + } catch (IOException e) { + e.printStackTrace(); + } + return properties; + } + + private static String getDataSource() { + return getProperties().getProperty("datasource"); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java index 3d1ce33..c1da088 100644 --- a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java @@ -36,9 +36,9 @@ public static AnimalDaoMem getInstance() { } @Override - public void add(Animal product) { - product.setId(data.size() + 1); - data.add(product); + public void add(Animal animal) { + animal.setId(data.size() + 1); + data.add(animal); } @Override diff --git a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java index 55032d9..8efb87f 100644 --- a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java +++ b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java @@ -69,15 +69,4 @@ public ResultSet executeQuery(String query) throws SQLException { } return null; } - - public static void main(String[] args) throws SQLException { - CodecoolShopDB cdb = CodecoolShopDB.getInstance(); - - ResultSet birds = cdb.executeQuery("select * from animals where species='Bird'"); - while(birds.next()) { - System.out.println(birds.getString("name")); - } - cdb.executeUpdate("insert into animals values(default, 'name', 'Mammal', 4000, 'USD', 'desc', 'url')"); - cdb.executeUpdate("delete from animals where name = 'name' and description = 'desc'"); - } } diff --git a/src/main/java/com/codecool/shop/model/Animal.java b/src/main/java/com/codecool/shop/model/Animal.java index 254af95..0acf501 100644 --- a/src/main/java/com/codecool/shop/model/Animal.java +++ b/src/main/java/com/codecool/shop/model/Animal.java @@ -2,7 +2,6 @@ import com.codecool.shop.dao.implementation.DB.ZooDaoDB; import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import java.util.Currency; From c59b3e8bc051a905de3e330e931c220febcaac14 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 16:34:43 +0200 Subject: [PATCH 71/76] Parameterized tests --- .../codecool/shop/tests/TestAnimalDao.java | 47 ++++++++--------- .../codecool/shop/tests/TestSpeciesDao.java | 51 ++++++++++-------- .../com/codecool/shop/tests/TestZooDao.java | 52 +++++++++++-------- 3 files changed, 80 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java index cec19a7..c96c423 100644 --- a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -3,37 +3,34 @@ import com.codecool.shop.dao.AnimalDao; import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; -import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; -import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; -import com.codecool.shop.model.Animal; -import com.codecool.shop.model.Species; -import com.codecool.shop.model.Zoo; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; public class TestAnimalDao { - private AnimalDao animalDao; - /** - * Make a new instance every time before running a test - */ - @BeforeEach - void setup() { - animalDao = AnimalDaoMem.getInstance(); + private static Stream daos() { + return Stream.of( + AnimalDaoMem.getInstance(), + AnimalDaoDB.getInstance() + ); } - @Test - void testFind() { + @Disabled + @ParameterizedTest + @MethodSource("daos") + void testFind(AnimalDao dao) { String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Montgomery Zoo"; - assertEquals(expected, animalDao.find(1).toString()); + assertEquals(expected, dao.find(1).toString()); } -// @Test +// @ParameterizedTest +// @MethodSource("daos") // void testGetBySupplier() { // Zoo zoo = ZooDaoMem.getInstance().find(1); // List expected = new ArrayList<>(); @@ -44,7 +41,8 @@ void testFind() { // assertEquals(animalDao.getBy(zoo), expected); // } // -// @Test +// @ParameterizedTest +// @MethodSource("daos") // void testGetByProductCategory() { // Species productCategory = SpeciesDaoMem.getInstance().find(1); // List expected = new ArrayList<>(); @@ -63,8 +61,9 @@ void testFind() { // assertEquals(animalDao.getBy(productCategory), expected); // } - @Test - void testGetAll() { - assertEquals(48, animalDao.getAll().size()); + @ParameterizedTest + @MethodSource("daos") + void testGetAll(AnimalDao dao) { + assertEquals(48, dao.getAll().size()); } } diff --git a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java index 33e7ba3..c1cf2f7 100644 --- a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java +++ b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java @@ -1,45 +1,50 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; import com.codecool.shop.model.Species; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; public class TestSpeciesDao { - private SpeciesDao speciesDao; - - /** - * Make a new instance every time before running a test - */ - @BeforeEach - void setup() { - speciesDao = SpeciesDaoMem.getInstance(); + + private static Stream daos() { + return Stream.of( + SpeciesDaoMem.getInstance(), + SpeciesDaoDB.getInstance() + ); } - @Test - void testAdd() { + @ParameterizedTest + @MethodSource("daos") + void testAdd(SpeciesDao dao) { Species newSpecies = new Species("Sample", "Sample", "Sample"); - speciesDao.add(newSpecies); - assert(speciesDao.getAll().contains(newSpecies)); + dao.add(newSpecies); + assertEquals(5, dao.getAll().size()); } - @Test - void testFindById() { + @ParameterizedTest + @MethodSource("daos") + void testFindById(SpeciesDao dao) { String expected = "id: 1,name: Bird, family: Vertebrate, description: Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; - assertEquals(expected, speciesDao.find(1).toString()); + assertEquals(expected, dao.find(1).toString()); } - @Test - void testFindByName() { + @ParameterizedTest + @MethodSource("daos") + void testFindByName(SpeciesDao dao) { String expected = "id: 1,name: Bird, family: Vertebrate, description: Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; - assertEquals(expected, speciesDao.find("Bird").toString()); + assertEquals(expected, dao.find("Bird").toString()); } - @Test - void testGetAll() { - assertEquals(5, speciesDao.getAll().size()); + @ParameterizedTest + @MethodSource("daos") + void testGetAll(SpeciesDao dao) { + assertEquals(5, dao.getAll().size()); } } diff --git a/src/main/java/com/codecool/shop/tests/TestZooDao.java b/src/main/java/com/codecool/shop/tests/TestZooDao.java index 64002b0..9ca04f6 100644 --- a/src/main/java/com/codecool/shop/tests/TestZooDao.java +++ b/src/main/java/com/codecool/shop/tests/TestZooDao.java @@ -1,45 +1,51 @@ package com.codecool.shop.tests; import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; import com.codecool.shop.model.Zoo; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; public class TestZooDao { - private ZooDao zooDao; - - /** - * Make a new instance every time before running a test - */ - @BeforeEach - void setup() { - zooDao = ZooDaoMem.getInstance(); + + private static Stream daos() { + return Stream.of( + ZooDaoMem.getInstance(), + ZooDaoDB.getInstance() + ); } - @Test - void testAdd() { + @ParameterizedTest + @MethodSource("daos") + void testAdd(ZooDao dao) { Zoo newZoo = new Zoo("Sample", "Sample", "Sample", "Sample"); - zooDao.add(newZoo); - assert(zooDao.getAll().contains(newZoo)); + dao.add(newZoo); + assertEquals(13, dao.getAll().size()); } - @Test - void testFindById() { + @ParameterizedTest + @MethodSource("daos") + void testFindById(ZooDao dao) { String expected = "id: 1, name: Montgomery Zoo, description: Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species."; - assertEquals(expected, zooDao.find(1).toString()); + assertEquals(expected, dao.find(1).toString()); } - @Test - void testFindByName() { + @ParameterizedTest + @MethodSource("daos") + void testFindByName(ZooDao dao) { String expected = "id: 1, name: Montgomery Zoo, description: Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species."; - assertEquals(expected, zooDao.find("Montgomery Zoo").toString()); + assertEquals(expected, dao.find("Montgomery Zoo").toString()); } - @Test - void testGetAll() { - assertEquals(13, zooDao.getAll().size()); + @ParameterizedTest + @MethodSource("daos") + void testGetAll(ZooDao dao) { + assertEquals(13, dao.getAll().size()); } } From 1c4f0006bd8d8a7a18cf1faf532190dcc97ed978 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 19:39:32 +0200 Subject: [PATCH 72/76] refactored parameterized tests --- .../codecool/shop/tests/TestAnimalDao.java | 39 +++---------------- .../codecool/shop/tests/TestSpeciesDao.java | 19 +++++++-- .../com/codecool/shop/tests/TestZooDao.java | 17 ++++++-- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java index c96c423..741e5c0 100644 --- a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -25,42 +25,15 @@ private static Stream daos() { @ParameterizedTest @MethodSource("daos") void testFind(AnimalDao dao) { - String expected = "id: 1, name: Griffon Vulture, defaultPrice: 1990,000000, defaultCurrency: USD, species: Bird, zoo: Montgomery Zoo"; + String expected = "id: 1, " + + "name: Griffon Vulture, " + + "defaultPrice: 1990,000000, " + + "defaultCurrency: USD, " + + "species: Bird, " + + "zoo: Montgomery Zoo"; assertEquals(expected, dao.find(1).toString()); } -// @ParameterizedTest -// @MethodSource("daos") -// void testGetBySupplier() { -// Zoo zoo = ZooDaoMem.getInstance().find(1); -// List expected = new ArrayList<>(); -// expected.add(animalDao.find(12)); -// expected.add(animalDao.find(24)); -// expected.add(animalDao.find(36)); -// expected.add(animalDao.find(48)); -// assertEquals(animalDao.getBy(zoo), expected); -// } -// -// @ParameterizedTest -// @MethodSource("daos") -// void testGetByProductCategory() { -// Species productCategory = SpeciesDaoMem.getInstance().find(1); -// List expected = new ArrayList<>(); -// expected.add(animalDao.find(1)); -// expected.add(animalDao.find(2)); -// expected.add(animalDao.find(3)); -// expected.add(animalDao.find(4)); -// expected.add(animalDao.find(5)); -// expected.add(animalDao.find(6)); -// expected.add(animalDao.find(7)); -// expected.add(animalDao.find(8)); -// expected.add(animalDao.find(9)); -// expected.add(animalDao.find(10)); -// expected.add(animalDao.find(11)); -// expected.add(animalDao.find(12)); -// assertEquals(animalDao.getBy(productCategory), expected); -// } - @ParameterizedTest @MethodSource("daos") void testGetAll(AnimalDao dao) { diff --git a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java index c1cf2f7..5b36608 100644 --- a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java +++ b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java @@ -4,13 +4,14 @@ import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; import com.codecool.shop.model.Species; + import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import java.util.stream.Stream; - import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.stream.Stream; + public class TestSpeciesDao { private static Stream daos() { @@ -31,14 +32,24 @@ void testAdd(SpeciesDao dao) { @ParameterizedTest @MethodSource("daos") void testFindById(SpeciesDao dao) { - String expected = "id: 1,name: Bird, family: Vertebrate, description: Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; + String expected = "id: 1," + + "name: Bird, " + + "family: Vertebrate, " + + "description: Birds (Aves) are a group of endothermic vertebrates, " + + "characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, " + + "a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; assertEquals(expected, dao.find(1).toString()); } @ParameterizedTest @MethodSource("daos") void testFindByName(SpeciesDao dao) { - String expected = "id: 1,name: Bird, family: Vertebrate, description: Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; + String expected = "id: 1," + + "name: Bird, " + + "family: Vertebrate, " + + "description: Birds (Aves) are a group of endothermic vertebrates, " + + "characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, " + + "a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; assertEquals(expected, dao.find("Bird").toString()); } diff --git a/src/main/java/com/codecool/shop/tests/TestZooDao.java b/src/main/java/com/codecool/shop/tests/TestZooDao.java index 9ca04f6..e285ab9 100644 --- a/src/main/java/com/codecool/shop/tests/TestZooDao.java +++ b/src/main/java/com/codecool/shop/tests/TestZooDao.java @@ -24,22 +24,33 @@ private static Stream daos() { @ParameterizedTest @MethodSource("daos") void testAdd(ZooDao dao) { + int expected = dao.getAll().size() + 1; Zoo newZoo = new Zoo("Sample", "Sample", "Sample", "Sample"); dao.add(newZoo); - assertEquals(13, dao.getAll().size()); + assertEquals(expected, dao.getAll().size()); } @ParameterizedTest @MethodSource("daos") void testFindById(ZooDao dao) { - String expected = "id: 1, name: Montgomery Zoo, description: Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species."; + String expected = "id: 1, " + + "name: Montgomery Zoo, " + + "description: Montgomery Zoo is a 40-acre (16 ha) zoo " + + "located on the north side of Montgomery, Alabama. The zoo is an independent city family, " + + "and is aided by The Montgomery Area Zoolocal Society. " + + "It is home to approximately 750 animals representing 140 species."; assertEquals(expected, dao.find(1).toString()); } @ParameterizedTest @MethodSource("daos") void testFindByName(ZooDao dao) { - String expected = "id: 1, name: Montgomery Zoo, description: Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species."; + String expected = "id: 1, " + + "name: Montgomery Zoo, " + + "description: Montgomery Zoo is a 40-acre (16 ha) zoo " + + "located on the north side of Montgomery, Alabama. The zoo is an independent city family, " + + "and is aided by The Montgomery Area Zoolocal Society. " + + "It is home to approximately 750 animals representing 140 species."; assertEquals(expected, dao.find("Montgomery Zoo").toString()); } From c777dcb0d2e781a30019539250b451409afc8ddd Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Thu, 30 May 2019 20:15:07 +0200 Subject: [PATCH 73/76] test add() for animalDao --- .../com/codecool/shop/tests/TestAnimalDao.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java index 741e5c0..adfb012 100644 --- a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -4,6 +4,8 @@ import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -21,6 +23,22 @@ private static Stream daos() { ); } + @Disabled + @ParameterizedTest + @MethodSource("daos") + void testAdd(AnimalDao dao) { + Animal newAnimal = new Animal( + "Sample", + new Species("", "", ""), + 0f, + "USD", + "", + "" + ); + dao.add(newAnimal); + assertEquals(49, dao.getAll().size()); + } + @Disabled @ParameterizedTest @MethodSource("daos") From 4dd33148b330eea07fe3e7185efe5ffa7e14c950 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Sat, 7 Sep 2019 17:22:22 +0200 Subject: [PATCH 74/76] refactored tests --- .../com/codecool/shop/tests/TestAnimalDao.java | 14 ++++++-------- .../com/codecool/shop/tests/TestSpeciesDao.java | 16 +++++++++------- .../java/com/codecool/shop/tests/TestZooDao.java | 16 +++++++++------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java index adfb012..1bfc64d 100644 --- a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -6,7 +6,6 @@ import com.codecool.shop.model.Animal; import com.codecool.shop.model.Species; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -16,16 +15,15 @@ public class TestAnimalDao { - private static Stream daos() { + private static Stream getDAOs() { return Stream.of( AnimalDaoMem.getInstance(), AnimalDaoDB.getInstance() ); } - @Disabled @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testAdd(AnimalDao dao) { Animal newAnimal = new Animal( "Sample", @@ -39,11 +37,11 @@ void testAdd(AnimalDao dao) { assertEquals(49, dao.getAll().size()); } - @Disabled @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testFind(AnimalDao dao) { - String expected = "id: 1, " + + String expected = + "id: 1, " + "name: Griffon Vulture, " + "defaultPrice: 1990,000000, " + "defaultCurrency: USD, " + @@ -53,7 +51,7 @@ void testFind(AnimalDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testGetAll(AnimalDao dao) { assertEquals(48, dao.getAll().size()); } diff --git a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java index 5b36608..0efaa23 100644 --- a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java +++ b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java @@ -14,7 +14,7 @@ public class TestSpeciesDao { - private static Stream daos() { + private static Stream getDAOs() { return Stream.of( SpeciesDaoMem.getInstance(), SpeciesDaoDB.getInstance() @@ -22,7 +22,7 @@ private static Stream daos() { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testAdd(SpeciesDao dao) { Species newSpecies = new Species("Sample", "Sample", "Sample"); dao.add(newSpecies); @@ -30,9 +30,10 @@ void testAdd(SpeciesDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testFindById(SpeciesDao dao) { - String expected = "id: 1," + + String expected = + "id: 1," + "name: Bird, " + "family: Vertebrate, " + "description: Birds (Aves) are a group of endothermic vertebrates, " + @@ -42,9 +43,10 @@ void testFindById(SpeciesDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testFindByName(SpeciesDao dao) { - String expected = "id: 1," + + String expected = + "id: 1," + "name: Bird, " + "family: Vertebrate, " + "description: Birds (Aves) are a group of endothermic vertebrates, " + @@ -54,7 +56,7 @@ void testFindByName(SpeciesDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testGetAll(SpeciesDao dao) { assertEquals(5, dao.getAll().size()); } diff --git a/src/main/java/com/codecool/shop/tests/TestZooDao.java b/src/main/java/com/codecool/shop/tests/TestZooDao.java index e285ab9..24f247a 100644 --- a/src/main/java/com/codecool/shop/tests/TestZooDao.java +++ b/src/main/java/com/codecool/shop/tests/TestZooDao.java @@ -14,7 +14,7 @@ public class TestZooDao { - private static Stream daos() { + private static Stream getDAOs() { return Stream.of( ZooDaoMem.getInstance(), ZooDaoDB.getInstance() @@ -22,7 +22,7 @@ private static Stream daos() { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testAdd(ZooDao dao) { int expected = dao.getAll().size() + 1; Zoo newZoo = new Zoo("Sample", "Sample", "Sample", "Sample"); @@ -31,9 +31,10 @@ void testAdd(ZooDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testFindById(ZooDao dao) { - String expected = "id: 1, " + + String expected = + "id: 1, " + "name: Montgomery Zoo, " + "description: Montgomery Zoo is a 40-acre (16 ha) zoo " + "located on the north side of Montgomery, Alabama. The zoo is an independent city family, " + @@ -43,9 +44,10 @@ void testFindById(ZooDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testFindByName(ZooDao dao) { - String expected = "id: 1, " + + String expected = + "id: 1, " + "name: Montgomery Zoo, " + "description: Montgomery Zoo is a 40-acre (16 ha) zoo " + "located on the north side of Montgomery, Alabama. The zoo is an independent city family, " + @@ -55,7 +57,7 @@ void testFindByName(ZooDao dao) { } @ParameterizedTest - @MethodSource("daos") + @MethodSource("getDAOs") void testGetAll(ZooDao dao) { assertEquals(13, dao.getAll().size()); } From ac6a0d269433cfcb7a6319edec08cd44b0a267c9 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 11 Sep 2019 11:29:23 +0200 Subject: [PATCH 75/76] orders added to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8d68e90..9022d84 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ target/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# order infos +orders/ \ No newline at end of file From ad392cf34372f344dfa25b4b40a36a2265c97155 Mon Sep 17 00:00:00 2001 From: zoltanNemeth Date: Wed, 11 Sep 2019 11:59:31 +0200 Subject: [PATCH 76/76] updated readme --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb24060..911b5e1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,17 @@ # Codecool Online Shop -Java SE: Web Project skeleton +Java SE: Web Project in Codecool + +A simple demo webshop made with Java, Jetty, Thymeleaf, PostgreSQL and JUnit. # Install -Import this project to IntelliJ as a Maven project. -IntelliJ can auto-install the dependencies based on the pom.xml +Import this project as a Maven project. + +Create a PostgreSQL database naming codecoolshop listening on port: localhost:5432 + +Set environmental variables according to lines 12-13 of CodecoolShopDB.java + +Run server with command mvn jetty:run + +Run tests as JUnit5 tests (also add JUnit5 to classpath)