/
ProductService.java
36 lines (24 loc) · 982 Bytes
/
ProductService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.github.lofi.client;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class ProductService {
private static Logger logger = Logger.getLogger(ProductService.class.getName());
private ProductIdbRepository productRepository;
private ProductRandomCreator productRandomCreator;
@Inject
public ProductService(ProductIdbRepository productRepository, ProductRandomCreator productRandomCreator) {
this.productRepository = productRepository;
this.productRandomCreator = productRandomCreator;
}
public Product createProduct() {
String key = productRandomCreator.getRandomId();
String type = productRandomCreator.geRandomType();
Integer price = productRandomCreator.getRandomPrice();
Product product = new Product.Builder(key, "Lofi " + key).setType(type).setAmount(10).setPrice(price).build();
logger.info(product.toString());
productRepository.persist(product);
return product;
}
}