/*
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pl.com.bottega.ecommerce.sales.domain.equivalent;
import java.util.List;
import javax.inject.Inject;
import pl.com.bottega.ddd.annotations.domain.DomainService;
import pl.com.bottega.ecommerce.sales.domain.client.Client;
import pl.com.bottega.ecommerce.sales.domain.productscatalog.Product;
import pl.com.bottega.ecommerce.sales.domain.productscatalog.ProductRepository;
import pl.com.bottega.ecommerce.sales.readmodel.offer.Offer;
import pl.com.bottega.ecommerce.sharedkernel.specification.Specification;
/**
* Sample Decision Support feature: suggests equivalent of the product based on client's habits.
*
* @author Slawek
*
*/
@DomainService
public class SuggestionService {
@Inject
private ProductRepository productRepository;
@Inject
private Offer offer;
@Inject
private ProductSpecificationFactory productSpecificationFactory;
public Product suggestEquivalent(Product problematicProduct, Client client) {
List<Product> expiringProducts = productRepository.findProductWhereBestBeforeExpiredIn(5);
Specification<Product> specification = productSpecificationFactory.create(client, problematicProduct);
for (Product suggestedProduct : expiringProducts) {
if (specification.isSatisfiedBy(suggestedProduct))
return suggestedProduct;
}
return null;
}
}