package devopsdistilled.operp.server.context.items;

import javax.inject.Inject;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.rmi.RmiServiceExporter;
import devopsdistilled.operp.server.data.service.items.BrandService;
import devopsdistilled.operp.server.data.service.items.CategoryService;
import devopsdistilled.operp.server.data.service.items.ItemService;
import devopsdistilled.operp.server.data.service.items.ManufacturerService;
import devopsdistilled.operp.server.data.service.items.ProductService;
import devopsdistilled.operp.server.data.service.stock.StockService;
import devopsdistilled.operp.server.data.service.stock.WarehouseService;

@Configuration
public class RmiContext {

	@Inject
	private ItemService itemService;

	@Inject
	private ProductService productService;

	@Inject
	private CategoryService categoryService;

	@Inject
	private BrandService brandService;

	@Inject
	private StockService stockService;

	@Inject
	private WarehouseService warehouseService;

	@Inject
	private ManufacturerService manufacturerService;

	@Bean
	public RmiServiceExporter rmiItemServiceExporter() {
		RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
		rmiServiceExporter.setServiceName("ItemService");
		rmiServiceExporter.setServiceInterface(ItemService.class);
		rmiServiceExporter.setService(itemService);
		rmiServiceExporter.setRegistryPort(1099); // default
		return rmiServiceExporter;
	}

	@Bean
	public RmiServiceExporter rmiProductServiceExporter() {
		RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
		rmiServiceExporter.setServiceName("ProductService");
		rmiServiceExporter.setServiceInterface(ProductService.class);
		rmiServiceExporter.setService(productService);
		rmiServiceExporter.setRegistryPort(1099);
		return rmiServiceExporter;
	}

	@Bean
	public RmiServiceExporter rmiBrandServiceExporter() {
		RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
		rmiServiceExporter.setServiceName("BrandService");
		rmiServiceExporter.setServiceInterface(BrandService.class);
		rmiServiceExporter.setService(brandService);
		rmiServiceExporter.setRegistryPort(1099);
		return rmiServiceExporter;
	}

	@Bean
	public RmiServiceExporter rmiStockServiceExporter() {
		RmiServiceExporter rmiServiceExportor = new RmiServiceExporter();
		rmiServiceExportor.setServiceName("StockService");
		rmiServiceExportor.setServiceInterface(StockService.class);
		rmiServiceExportor.setService(stockService);
		rmiServiceExportor.setRegistryPort(1099);
		return rmiServiceExportor;

	}

	@Bean
	public RmiServiceExporter rmiWarehouseServiceExporter() {
		RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
		rmiServiceExporter.setServiceName("WarehouseService");
		rmiServiceExporter.setServiceInterface(WarehouseService.class);
		rmiServiceExporter.setService(warehouseService);
		return rmiServiceExporter;
	}

	@Bean
	public RmiServiceExporter rmiCategoryServiceExporter() {
		RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
		rmiServiceExporter.setServiceName("CategoryService");
		rmiServiceExporter.setServiceInterface(CategoryService.class);
		rmiServiceExporter.setService(categoryService);
		rmiServiceExporter.setRegistryPort(1099);
		return rmiServiceExporter;
	}

	@Bean
	public RmiServiceExporter rmiManufacturerServiceExporter() {
		RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
		rmiServiceExporter.setServiceName("ManufacturerService");
		rmiServiceExporter.setServiceInterface(ManufacturerService.class);
		rmiServiceExporter.setService(manufacturerService);
		rmiServiceExporter.setRegistryPort(1099);
		return rmiServiceExporter;
	}

}

@@ -248,16 +248,17 @@
 porter;%0A
+%0A
 import d
@@ -608,150 +608,8 @@
 ice;
-%0Aimport devopsdistilled.operp.server.data.service.stock.StockService;%0Aimport devopsdistilled.operp.server.data.service.stock.WarehouseService;
 %0A%0A@C
@@ -634,16 +634,20 @@
 c class 
+Item
 RmiConte
@@ -848,108 +848,8 @@
 e;%0A%0A
-%09@Inject%0A%09private StockService stockService;%0A%0A%09@Inject%0A%09private WarehouseService warehouseService;%0A%0A
 %09@In
@@ -2030,719 +2030,8 @@
 %09%7D%0A%0A
-%09@Bean%0A%09public RmiServiceExporter rmiStockServiceExporter() %7B%0A%09%09RmiServiceExporter rmiServiceExportor = new RmiServiceExporter();%0A%09%09rmiServiceExportor.setServiceName(%22StockService%22);%0A%09%09rmiServiceExportor.setServiceInterface(StockService.class);%0A%09%09rmiServiceExportor.setService(stockService);%0A%09%09rmiServiceExportor.setRegistryPort(1099);%0A%09%09return rmiServiceExportor;%0A%0A%09%7D%0A%0A%09@Bean%0A%09public RmiServiceExporter rmiWarehouseServiceExporter() %7B%0A%09%09RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();%0A%09%09rmiServiceExporter.setServiceName(%22WarehouseService%22);%0A%09%09rmiServiceExporter.setServiceInterface(WarehouseService.class);%0A%09%09rmiServiceExporter.setService(warehouseService);%0A%09%09return rmiServiceExporter;%0A%09%7D%0A%0A
 %09@Be

Add RMI Context for item-module