Added product retriever with tests
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package de.rwu.easydrop.service.retriever;
|
||||
|
||||
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.model.Product;
|
||||
import de.rwu.easydrop.service.mapping.ProductMapper;
|
||||
import de.rwu.easydrop.service.validation.ProductValidator;
|
||||
|
||||
/**
|
||||
* Retrieves Product Objects from various data sources.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
public class ProductRetriever {
|
||||
/**
|
||||
* Data source factory.
|
||||
*/
|
||||
private DataSourceFactory dataSourceFactory;
|
||||
|
||||
/**
|
||||
* @param newDataSourceFactory the dataSourceFactory to set
|
||||
*/
|
||||
public void setDataSourceFactory(final DataSourceFactory newDataSourceFactory) {
|
||||
this.dataSourceFactory = newDataSourceFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newDataSourceFactory
|
||||
*/
|
||||
public ProductRetriever(final DataSourceFactory newDataSourceFactory) {
|
||||
this.setDataSourceFactory(newDataSourceFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a product from Amazon.
|
||||
*
|
||||
* @param asin Product identifier
|
||||
* @return Product from Amazon
|
||||
*/
|
||||
public Product getProductFromAmazon(final String asin) {
|
||||
AmazonProductDataSource dataSource = dataSourceFactory.createAmazonProductDataSource();
|
||||
ProductDTO dto = dataSource.getProductDTOById(asin);
|
||||
|
||||
Product product = ProductMapper.mapProductFromDTO(dto);
|
||||
ProductValidator.validate(product);
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a product from eBay.
|
||||
*
|
||||
* @param query Product search query
|
||||
* @return Product from eBay
|
||||
*/
|
||||
public Product getProductFromEbay(final String query) {
|
||||
EbayItemDataSource dataSource = dataSourceFactory.createEbayItemDataSource();
|
||||
ProductDTO dto = dataSource.getProductDTOById(query);
|
||||
|
||||
Product product = ProductMapper.mapProductFromDTO(dto);
|
||||
ProductValidator.validate(product);
|
||||
|
||||
return product;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Retrieves Objects from a data source.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
package de.rwu.easydrop.service.retriever;
|
||||
Reference in New Issue
Block a user