From 286edb33ed48fe24fbc541ee6a13508a0093c85b Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 30 May 2020 11:52:30 +0200 Subject: [PATCH 01/10] show supplier name at offered article page --- .../suppliers/SupplierOfferController.java | 24 ++++++------------- .../entities/supplier/ArticleOffer.java | 3 ++- .../intern/offeredArticles/index.html | 2 +- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java index 3ef21bf..7d27059 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java @@ -30,7 +30,8 @@ public class SupplierOfferController { for (ArticleOffer article : offersRepository.findAll()) { UImodelOfferedArticle tmp = new UImodelOfferedArticle(); - tmp.addData(article, "supplierName01", 4884, articleRepository.findArticleIDByRelatedID(article.id)); //TODO display supplier name with link + tmp.addData(article, articleRepository.findArticleIDByRelatedID(article.id)); // TODO display supplier name + // with link totals.add(tmp); } @@ -40,16 +41,15 @@ public class SupplierOfferController { public class UImodelOfferedArticle { - long offer_id; + long offer_id; String title; String manufacturer; String articlenumber; String supplierName; - int supplierId; String price; String ads; int listedArticleId; - boolean offerIsListed; //true --> offered article is listed + boolean offerIsListed; // true --> offered article is listed public long getOffer_id() { return offer_id; @@ -58,7 +58,7 @@ public class SupplierOfferController { public void setOffer_id(long offer_id) { this.offer_id = offer_id; } - + public boolean isOfferIsListed() { return offerIsListed; } @@ -99,14 +99,6 @@ public class SupplierOfferController { this.supplierName = supplierName; } - public int getSupplierId() { - return supplierId; - } - - public void setSupplierId(int supplierId) { - this.supplierId = supplierId; - } - public String getPrice() { return price; } @@ -131,15 +123,13 @@ public class SupplierOfferController { this.listedArticleId = listedArticleId; } - public void addData(ArticleOffer article, String supplierName, int supplierId, - Optional listedArticleId) { + public void addData(ArticleOffer article, Optional listedArticleId) { this.offer_id = article.id; this.title = article.title; this.manufacturer = article.manufacturer; this.articlenumber = article.articleNumber; - this.supplierName = supplierName; - this.supplierId = supplierId; + this.supplierName = article.cheapestSupplier.name; this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100)); this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein"; diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index 405fb4a..8c20099 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -28,5 +28,6 @@ public class ArticleOffer { public boolean shouldBeAdvertised; - + @ManyToOne(optional = false) + public Supplier cheapestSupplier; } diff --git a/prototype/src/main/resources/templates/intern/offeredArticles/index.html b/prototype/src/main/resources/templates/intern/offeredArticles/index.html index 79d926a..04d9a12 100644 --- a/prototype/src/main/resources/templates/intern/offeredArticles/index.html +++ b/prototype/src/main/resources/templates/intern/offeredArticles/index.html @@ -44,7 +44,7 @@ - + From 1b2e75a82c29eeb7807179063f44cd56fadadb43 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 30 May 2020 12:29:40 +0200 Subject: [PATCH 02/10] updates scripts --- prototype/scripts/addarticles.sql | 13 +++++++++++-- prototype/scripts/addsupplier.sql | 6 ++++++ .../intern/suppliers/SupplierOfferController.java | 3 +-- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 prototype/scripts/addsupplier.sql diff --git a/prototype/scripts/addarticles.sql b/prototype/scripts/addarticles.sql index b60497d..e81c174 100644 --- a/prototype/scripts/addarticles.sql +++ b/prototype/scripts/addarticles.sql @@ -1,6 +1,15 @@ -INSERT INTO article_offers ("manufacturer", "article_number", "price_per_unit_net", "title", "vat_percent", "should_be_advertised") -VALUES ("McDonalds", "1", 4242, "McPizza", 7, 1); +/* +* add a supplier first +*/ +INSERT INTO article_offers ("manufacturer", "article_number", "price_per_unit_net", "title", "vat_percent", "should_be_advertised", "cheapest_supplier_id") +VALUES ("McDonalds", "1", 4242, "McPizza", 7, 1, 1); + + + +/* +* There is no need for the add article, you can add one form the UI on the offerd article page +*/ INSERT INTO articles ("related_id", "shop_price_per_unit_net_cent", "warehouse_units_per_slot", "should_reorder", "reorder_max_price", "title", "description", "image_id") VALUES (1, 19.99, 10, 1, 15, "Huge Hamburger", "This huge Hamburger is awesome!", NULL); diff --git a/prototype/scripts/addsupplier.sql b/prototype/scripts/addsupplier.sql new file mode 100644 index 0000000..a56f4ed --- /dev/null +++ b/prototype/scripts/addsupplier.sql @@ -0,0 +1,6 @@ + +INSERT INTO suppliers ("api_url", "name", "uuid") +VALUES ("https://api.com", "Conrad", "fdfdfg4gdfgdf4gfg"); + + + diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java index 7d27059..ca71682 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java @@ -30,8 +30,7 @@ public class SupplierOfferController { for (ArticleOffer article : offersRepository.findAll()) { UImodelOfferedArticle tmp = new UImodelOfferedArticle(); - tmp.addData(article, articleRepository.findArticleIDByRelatedID(article.id)); // TODO display supplier name - // with link + tmp.addData(article, articleRepository.findArticleIDByRelatedID(article.id)); totals.add(tmp); } From 407229f15d97001f6ffccd72cacb5f961bd5b2b8 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 30 May 2020 16:49:20 +0200 Subject: [PATCH 03/10] changed cheapest supplier ref in offered article entity --- .../java/org/hso/ecommerce/entities/supplier/ArticleOffer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index 8c20099..41296ba 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -28,6 +28,6 @@ public class ArticleOffer { public boolean shouldBeAdvertised; - @ManyToOne(optional = false) + @ManyToOne(optional = true) public Supplier cheapestSupplier; } From e7e3864b4c93f30c44abc6d5dccf8f8833cfd343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BCrderer?= Date: Sat, 30 May 2020 18:25:23 +0200 Subject: [PATCH 04/10] Store the cheapest supplier for each offered article in the database --- .../hso/ecommerce/action/cronjob/UpdateOffersAction.java | 6 +++++- .../org/hso/ecommerce/entities/supplier/ArticleOffer.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java b/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java index f095381..e21869e 100644 --- a/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java +++ b/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java @@ -30,9 +30,10 @@ public class UpdateOffersAction { public List finish() { HashMap availableOffers = mapOffers(); - // Reset all advertise-flags first. They are set again below. + // Reset all advertise-flags and supplier relations first. They are set again below. for (ArticleOffer offer : availableOffers.values()) { offer.shouldBeAdvertised = false; + offer.cheapestSupplier = null; } for (Entry cheapestOffer : cheapestOffer.entrySet()) { @@ -47,7 +48,10 @@ public class UpdateOffersAction { } Article currentOfferedArticle = cheapestOffer.getValue().apiSupplier.findArticle(manufacturer, articleNumber); + currentOffer.title = currentOfferedArticle.title; currentOffer.vatPercent = currentOfferedArticle.vatPercent; + currentOffer.cheapestSupplier = cheapestOffer.getValue().dbSupplier; + currentOffer.pricePerUnitNet = currentOfferedArticle.pricePerUnitNet; // Set advertise-flag if any supplier wants it to be set if (currentOfferedArticle.shouldBeAdvertised) { diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index 405fb4a..41296ba 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -28,5 +28,6 @@ public class ArticleOffer { public boolean shouldBeAdvertised; - + @ManyToOne(optional = true) + public Supplier cheapestSupplier; } From 9238162a4c3d6b4c19cd99f0bde73ed0873228ad Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 29 May 2020 11:06:00 +0200 Subject: [PATCH 05/10] implement better search --- .../action/shop/SearchByTermAction.java | 40 +++++++++++++++++++ .../controller/shop/ShopSearchController.java | 3 +- .../repos/shop/ArticleRepository.java | 5 ++- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 prototype/src/main/java/org/hso/ecommerce/action/shop/SearchByTermAction.java diff --git a/prototype/src/main/java/org/hso/ecommerce/action/shop/SearchByTermAction.java b/prototype/src/main/java/org/hso/ecommerce/action/shop/SearchByTermAction.java new file mode 100644 index 0000000..cfdfffe --- /dev/null +++ b/prototype/src/main/java/org/hso/ecommerce/action/shop/SearchByTermAction.java @@ -0,0 +1,40 @@ +package org.hso.ecommerce.action.shop; + +import org.hso.ecommerce.entities.shop.Article; +import org.hso.ecommerce.repos.shop.ArticleRepository; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SearchByTermAction { + + public static List
searchByTerm(String sourceTerm, ArticleRepository repository) { + + List terms = Arrays.asList(sourceTerm.split(" ")); + List
resultArticles = new ArrayList<>(); + + terms.forEach(term -> { + List
titleArticles = repository.getArticlesByTermInTitle(term); //search in Title + titleArticles.forEach(article -> { + if(!resultArticles.contains(article)){ + resultArticles.add(article); + } + }); + + }); + + terms.forEach(term -> { + List
descArticles = repository.getArticlesByTermInDescription(term); //search by Term + descArticles.forEach(article -> { + if(!resultArticles.contains(article)){ + resultArticles.add(article); + } + }); + + }); + + return resultArticles; + } +} diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java index 1d14c61..ad1d107 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java @@ -1,5 +1,6 @@ package org.hso.ecommerce.controller.shop; +import org.hso.ecommerce.action.shop.SearchByTermAction; import org.hso.ecommerce.entities.shop.Article; import org.hso.ecommerce.repos.shop.ArticleRepository; import org.hso.ecommerce.repos.shop.CategoryRepository; @@ -32,7 +33,7 @@ public class ShopSearchController { model.addAttribute("categories", categoryRepository.getCategories()); //for sidebar if (term != null) { //if search by Term - List
articles = articleRepository.getArticlesByTerm(term); //search by Term + List
articles = SearchByTermAction.searchByTerm(term, articleRepository); model.addAttribute("articles", articles); } else if (category != null) { //if search by Category List
articles = articleRepository.getArticlesByCategory(category); //search by Category diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index 0340f59..a7f7597 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -31,7 +31,10 @@ public interface ArticleRepository extends JpaRepository { Optional findArticleIDByRelatedID(@Param("relatedId") long relatedId); @Query(value = "Select a.* from articles as a, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and a.title LIKE %:term% group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true) - List
getArticlesByTerm(String term); + List
getArticlesByTermInTitle(String term); + + @Query(value = "Select a.* from articles as a, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and a.description LIKE %:term% group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true) + List
getArticlesByTermInDescription(String term); @Query(value = "Select a.* from articles as a, categories as c, article_categories_bindings as acb, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and acb.articles_id = a.id and acb.categories_id = c.id and c.name = :category group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true) List
getArticlesByCategory(String category); From 38fcda708fe118bd59c8480e413a78c1721fbdef Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 1 Jun 2020 10:53:10 +0200 Subject: [PATCH 06/10] check if article.image is null --- .../controller/intern/InternArticleController.java | 13 +++++++++---- .../controller/shop/ShopArticleController.java | 9 ++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java index 35d76f8..62b615d 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java @@ -148,9 +148,9 @@ public class InternArticleController { File tmpFile = new File(defaultImagePath); // test if default img file exits if (!tmpFile.exists()) { - // fallback if the file not exists + // fallback if the file not exists // create new file - BufferedImage bufferedImage = new BufferedImage(422, 428, BufferedImage.TYPE_INT_RGB); + BufferedImage bufferedImage = new BufferedImage(422, 428, BufferedImage.TYPE_INT_RGB); try { ImageIO.write(bufferedImage, "jpg", new File(defaultImagePath)); // save new file on disk } catch (IOException e) { @@ -208,7 +208,10 @@ public class InternArticleController { public long id; void addListedArticle(Article article, int stock) { - this.imgPath = article.image.path; + + if (article.image != null) { + this.imgPath = article.image.path; + } this.title = article.title; this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100)); this.price = String.format("%.2f", ((float) article.getPriceGross() / 100)); @@ -338,7 +341,9 @@ public class InternArticleController { } void addArticle(Article article, int stock) { - this.imgPath = article.image.path; + if (article.image != null) { + this.imgPath = article.image.path; + } this.title = article.title; this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100)); this.price = String.format("%.2f", ((float) article.getPriceGross() / 100)); diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java index 235669c..18144f7 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java @@ -100,8 +100,11 @@ public class ShopArticleController { @PathVariable("id") Long id ) throws IOException { Article article = articleRepository.findArticleById(id); - InputStream in = new FileInputStream(article.image.path); - response.setContentType(MediaType.IMAGE_JPEG_VALUE); - IOUtils.copy(in, response.getOutputStream()); + + if(article.image != null) { + InputStream in = new FileInputStream(article.image.path); + response.setContentType(MediaType.IMAGE_JPEG_VALUE); + IOUtils.copy(in, response.getOutputStream()); + } } } \ No newline at end of file From 0fb1d5704e658bf0642697cc66432aa644250386 Mon Sep 17 00:00:00 2001 From: Danny Date: Mon, 1 Jun 2020 11:11:34 +0200 Subject: [PATCH 07/10] Bufix: After register, you now logged in --- .../org/hso/ecommerce/controller/RegisterController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java index a53e084..448af79 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java @@ -64,7 +64,10 @@ public class RegisterController { userRepository.save(newUser); // save newUser - return "redirect:/login"; + user = userRepository.findByEmail(username); + session.setAttribute("userId", user.get().getId()); + + return "redirect:/"; } @GetMapping("/register") From 922e3cadef4c875a922ab38519e7ddf07974333a Mon Sep 17 00:00:00 2001 From: Danny Date: Mon, 1 Jun 2020 11:13:03 +0200 Subject: [PATCH 08/10] Bugfix register --- .../java/org/hso/ecommerce/controller/RegisterController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java index 448af79..15acf9f 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import java.util.Optional; @Controller @@ -30,7 +31,8 @@ public class RegisterController { @RequestParam("name") String name, @RequestParam("address") String address, @RequestParam("type") String type, - @RequestParam("ad") String ad + @RequestParam("ad") String ad, + HttpSession session ) { Optional user = userRepository.findByEmail(username); From 839bebcd8912db2f0aad21745618df55637d7ed1 Mon Sep 17 00:00:00 2001 From: Hannes Date: Mon, 1 Jun 2020 11:58:08 +0200 Subject: [PATCH 09/10] trim searchterm --- .../org/hso/ecommerce/controller/shop/ShopSearchController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java index ad1d107..cacdafe 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java @@ -32,6 +32,8 @@ public class ShopSearchController { ) { model.addAttribute("categories", categoryRepository.getCategories()); //for sidebar + term = term.trim(); + if (term != null) { //if search by Term List
articles = SearchByTermAction.searchByTerm(term, articleRepository); model.addAttribute("articles", articles); From 6988d3f213f21bbedbee4de966d4dcd078c1a8bd Mon Sep 17 00:00:00 2001 From: Seil0 Date: Mon, 1 Jun 2020 17:10:04 +0200 Subject: [PATCH 10/10] minor code clean up --- .../controller/intern/suppliers/SupplierOfferController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java index ca71682..edc7bc2 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java @@ -26,7 +26,7 @@ public class SupplierOfferController { @GetMapping("supplierOffers") public String internListedArticles(Model model) { - List totals = new ArrayList(); + List totals = new ArrayList<>(); for (ArticleOffer article : offersRepository.findAll()) { UImodelOfferedArticle tmp = new UImodelOfferedArticle();