Connected application components
This commit is contained in:
@@ -5,6 +5,9 @@ import java.util.List;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.ProductCatalogue;
|
||||
import de.rwu.easydrop.util.ProductsConfig;
|
||||
@@ -17,6 +20,11 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class CatalogueRetriever {
|
||||
/**
|
||||
* Logging instance.
|
||||
*/
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogueRetriever.class);
|
||||
|
||||
/**
|
||||
* User-configured products.
|
||||
*/
|
||||
@@ -56,15 +64,14 @@ public class CatalogueRetriever {
|
||||
pCat.getProductName(), pCat.getDescription());
|
||||
|
||||
for (Product product : pCat.getProducts()) {
|
||||
Product newProduct = new Product();
|
||||
|
||||
newProduct = productRetriever.getProductFromWebshop(product.getDataOrigin(),
|
||||
Product newProduct = productRetriever.getProductFromWebshop(product.getDataOrigin(),
|
||||
product.getProductId());
|
||||
|
||||
newProductCatalogue.addProduct(newProduct);
|
||||
}
|
||||
|
||||
productCatalogues.add(newProductCatalogue);
|
||||
LOGGER.info("\nLoaded Catalogue: \n" + newProductCatalogue.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,40 @@
|
||||
package de.rwu.easydrop.service.retriever;
|
||||
|
||||
public class OfferRetriever {
|
||||
import de.rwu.easydrop.api.dto.OfferDTO;
|
||||
import de.rwu.easydrop.data.connector.OfferPersistenceInterface;
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.service.mapping.OfferMapper;
|
||||
|
||||
/**
|
||||
* Retrieves offer information from different sources.
|
||||
*
|
||||
* @since 0.3.0
|
||||
*/
|
||||
public class OfferRetriever {
|
||||
/**
|
||||
* Persistence interface.
|
||||
*/
|
||||
private OfferPersistenceInterface persistence;
|
||||
|
||||
/**
|
||||
* Creates an Offer Retriever.
|
||||
*
|
||||
* @param db Persistence Interface
|
||||
*/
|
||||
public OfferRetriever(final OfferPersistenceInterface db) {
|
||||
this.persistence = db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an offer from persistence.
|
||||
*
|
||||
* @param offerId
|
||||
* @return Offer from persistence
|
||||
*/
|
||||
public Offer getOfferFromPersistence(final String offerId) {
|
||||
OfferPersistenceInterface src = persistence;
|
||||
|
||||
OfferDTO dto = src.getOfferDTOById(offerId);
|
||||
return OfferMapper.mapOfferFromDTO(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import de.rwu.easydrop.api.client.AmazonProductDataSource;
|
||||
import de.rwu.easydrop.api.client.DataSourceFactory;
|
||||
import de.rwu.easydrop.api.client.EbayItemDataSource;
|
||||
import de.rwu.easydrop.api.dto.ProductDTO;
|
||||
import de.rwu.easydrop.data.connector.AbstractProductPersistence;
|
||||
import de.rwu.easydrop.data.connector.ProductPersistenceInterface;
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
import de.rwu.easydrop.service.mapping.ProductMapper;
|
||||
@@ -20,19 +20,20 @@ public class ProductRetriever {
|
||||
* Data source factory.
|
||||
*/
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
/**
|
||||
* @param newDataSourceFactory the WebshopFactory to set
|
||||
* Persistence interface.
|
||||
*/
|
||||
public void setWebshopFactory(final DataSourceFactory newDataSourceFactory) {
|
||||
this.dataSourceFactory = newDataSourceFactory;
|
||||
}
|
||||
private ProductPersistenceInterface persistence;
|
||||
|
||||
/**
|
||||
* @param newDataSourceFactory
|
||||
* @param newPersistence
|
||||
*/
|
||||
public ProductRetriever(final DataSourceFactory newDataSourceFactory) {
|
||||
this.setWebshopFactory(newDataSourceFactory);
|
||||
public ProductRetriever(
|
||||
final DataSourceFactory newDataSourceFactory,
|
||||
final ProductPersistenceInterface newPersistence) {
|
||||
this.dataSourceFactory = newDataSourceFactory;
|
||||
this.persistence = newPersistence;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,9 +75,7 @@ public class ProductRetriever {
|
||||
* @return Product from persistence
|
||||
*/
|
||||
public Product getProductFromPersistence(final String productId) {
|
||||
AbstractProductPersistence src = dataSourceFactory.createProductPersistenceDataSource();
|
||||
|
||||
ProductDTO dto = src.getProductDTOById(productId);
|
||||
ProductDTO dto = persistence.getProductDTOById(productId);
|
||||
Product product = ProductMapper.mapProductFromDTO(dto);
|
||||
ProductValidator.validate(product);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user