@@ -0,0 +1,2321 @@
+/**%0A * Created by Djidjelly Siclait on 11/26/2016.%0A */%0Apackage com.evapps.Service.CRUD;%0A%0Aimport com.evapps.Entity.History;%0Aimport com.evapps.Entity.Product;%0Aimport com.evapps.Repository.HistoryRepository;%0Aimport com.evapps.Repository.ProductRepository;%0Aimport freemarker.template.utility.NullArgumentException;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport javax.persistence.PersistenceException;%0Aimport java.util.Set;%0A%0A@Service%0Apublic class DeleteDataService %7B%0A%0A    // Repositories%0A    @Autowired%0A    private HistoryRepository historyRepository;%0A    @Autowired%0A    private ProductRepository productRepository;%0A%0A    // Deletes%0A    public void deleteRegisteredProduct(Integer productId) throws Exception%7B%0A%0A        if (!doesProductIdExist(productId))%0A            throw new IllegalArgumentException(%22This product does not exists%22);%0A%0A        try %7B%0A            Product product = productRepository.findByProductId(productId);%0A            %0A            // Applying Cascade%0A            for (History history:%0A                 historyRepository.findAll()) %7B%0A                // Fetching sets%0A                Set%3CProduct%3E browsingHistory = history.getBrowsingHistory();%0A                Set%3CProduct%3E shoppingCart = history.getShoppingCart();%0A%0A                // Removing the item%0A                browsingHistory.remove(product);%0A                shoppingCart.remove(product);%0A%0A                // Update History%0A                history.setBrowsingHistory(browsingHistory);%0A                history.setShoppingCart(shoppingCart);%0A                historyRepository.save(history);%0A            %7D%0A%0A            // Deleting Product%0A            productRepository.delete(product);%0A        %7D catch (PersistenceException exp)%7B%0A            throw new PersistenceException(%22Persistence Error --%3E %22 + exp.getMessage());%0A        %7D catch (NullArgumentException exp)%7B%0A            throw new NullArgumentException(%22Null Argument Error --%3E %22 + exp.getMessage());%0A        %7D catch (Exception exp)%7B%0A            throw new Exception(%22General Error --%3E %22 + exp.getMessage());%0A        %7D%0A    %7D%0A%0A    // Auxiliary Functions%0A    private boolean doesProductIdExist(Integer productId)%7B%0A        Product product = productRepository.findByProductId(productId);%0A        return (product != null);%0A    %7D%0A%7D%0A

Create DeleteData Service