1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.catalog.controller;
18
19 import java.text.ParseException;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
27 import org.apache.logging.log4j.catalog.api.dao.CatalogDao;
28 import org.apache.logging.log4j.catalog.api.Attribute;
29 import org.apache.logging.log4j.catalog.api.Category;
30 import org.apache.logging.log4j.catalog.api.Event;
31 import org.apache.logging.log4j.catalog.api.Product;
32 import org.apache.logging.log4j.catalog.jpa.converter.AttributeModelConverter;
33 import org.apache.logging.log4j.catalog.jpa.converter.CategoryModelConverter;
34 import org.apache.logging.log4j.catalog.jpa.converter.EventModelConverter;
35 import org.apache.logging.log4j.catalog.jpa.converter.ProductModelConverter;
36 import org.apache.logging.log4j.catalog.jpa.model.AttributeModel;
37 import org.apache.logging.log4j.catalog.jpa.model.CategoryModel;
38 import org.apache.logging.log4j.catalog.jpa.model.EventModel;
39 import org.apache.logging.log4j.catalog.jpa.model.ProductModel;
40 import org.apache.logging.log4j.catalog.jpa.service.AttributeService;
41 import org.apache.logging.log4j.catalog.jpa.service.CategoryService;
42 import org.apache.logging.log4j.catalog.jpa.service.EventService;
43 import org.apache.logging.log4j.catalog.jpa.service.ProductService;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.http.HttpStatus;
46 import org.springframework.http.ResponseEntity;
47 import org.springframework.web.bind.annotation.PathVariable;
48 import org.springframework.web.bind.annotation.PostMapping;
49 import org.springframework.web.bind.annotation.RequestMapping;
50 import org.springframework.web.bind.annotation.RequestMethod;
51 import org.springframework.web.bind.annotation.RequestParam;
52
53 import org.apache.logging.log4j.catalog.api.CatalogData;
54 import org.springframework.web.bind.annotation.RestController;
55
56
57
58
59 @RestController
60 public class CatalogController {
61
62
63 private static Logger logger = LogManager.getLogger(CatalogController.class);
64
65 @Autowired
66 private EventService eventService;
67
68 @Autowired
69 private AttributeService attributeService;
70
71 @Autowired
72 private ProductService productService;
73
74 @Autowired
75 private CategoryService categoryService;
76
77 @Autowired
78 private AttributeModelConverter attributeModelConverter;
79
80 @Autowired
81 private EventModelConverter eventModelConverter;
82
83 @Autowired
84 private ProductModelConverter productModelConverter;
85
86 @Autowired
87 private CategoryModelConverter categoryModelConverter;
88
89 @Autowired
90 private CatalogDao catalogDao;
91
92
93 @PostMapping(value = "catalog")
94 public ResponseEntity<?> saveCatalog() {
95 CatalogData catalogData = new CatalogData();
96 List<Attribute> attributes = new ArrayList<>();
97 for (AttributeModel attributeModel : attributeService.getAttributes()) {
98 attributes.add(attributeModelConverter.convert(attributeModel));
99 }
100 catalogData.setAttributes(attributes);
101 List<Event> events = new ArrayList<>();
102 for (EventModel eventModel : eventService.getEvents()) {
103 events.add(eventModelConverter.convert(eventModel));
104 }
105 catalogData.setEvents(events);
106 List<Category> categories = new ArrayList<>();
107 for (CategoryModel categoryModel : categoryService.getCategories()) {
108 categories.add(categoryModelConverter.convert(categoryModel));
109 }
110 catalogData.setCategories(categories);
111 List<Product> products = new ArrayList<>();
112 for (ProductModel productModel : productService.getProducts()) {
113 products.add(productModelConverter.convert(productModel));
114 }
115 catalogData.setProducts(products);
116 catalogDao.write(catalogData);
117 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 }