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/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/RegisterController.java b/prototype/src/main/java/org/hso/ecommerce/controller/RegisterController.java index a53e084..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); @@ -64,7 +66,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") 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 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..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 @@ -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; @@ -31,8 +32,10 @@ public class ShopSearchController { ) { model.addAttribute("categories", categoryRepository.getCategories()); //for sidebar + term = term.trim(); + 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);