package devopsdistilled.operp.client.items.controllers.impl;

import javax.inject.Inject;

import devopsdistilled.operp.client.items.controllers.CreateItemPaneController;
import devopsdistilled.operp.client.items.exceptions.ItemNameExistsException;
import devopsdistilled.operp.client.items.exceptions.ProductBrandPairExistsException;
import devopsdistilled.operp.client.items.models.BrandModel;
import devopsdistilled.operp.client.items.models.CreateItemPaneModel;
import devopsdistilled.operp.client.items.models.ItemModel;
import devopsdistilled.operp.client.items.models.ProductModel;
import devopsdistilled.operp.client.items.views.CreateItemPane;
import devopsdistilled.operp.server.data.entity.items.Item;

public class CreateItemPaneControllerImpl implements CreateItemPaneController {

	@Inject
	private CreateItemPaneModel model;

	@Inject
	private CreateItemPane view;

	@Inject
	private ItemModel itemModel;

	@Inject
	private ProductModel productModel;

	@Inject
	private BrandModel brandModel;

	@Override
	public void init() {
		view.init();
		model.registerObserver(view);
		productModel.registerObserver(view);
		brandModel.registerObserver(view);
	}

	@Override
	public void validate(Item item) throws ProductBrandPairExistsException,
			ItemNameExistsException {

		if (itemModel.getService().isProductBrandPairExists(item.getProduct(),
				item.getBrand())) {

			throw new ProductBrandPairExistsException();
		}

		if (itemModel.getService().isItemNameExists(item.getItemName())) {

			throw new ItemNameExistsException();
		}
	}

	@Override
	public Item save(Item item) {
		Item savedItem = itemModel.saveAndUpdateModel(item);
		return savedItem;
	}
}

@@ -234,32 +234,105 @@
 xistsException;%0A
+import devopsdistilled.operp.client.items.exceptions.NullFieldException;%0A
 import devopsdis
@@ -1345,18 +1345,202 @@
 xception
- %7B
+, NullFieldException %7B%0A%0A%09%09if (item.getItemName() == null %7C%7C item.getProduct() == null%0A%09%09%09%09%7C%7C item.getBrand() == null %7C%7C item.getPrice() == null) %7B%0A%0A%09%09%09throw new NullFieldException();%0A%09%09%7D
 %0A%0A%09%09if (

Check if fields are Null, if so, throws NullFieldException