import java.util.Objects;
import javax.ejb.EJB;
import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
import org.mxchange.jfinancials.database.product.BaseFinancialsProductDatabaseBean;
import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException;
import org.mxchange.jproduct.model.category.Category;
} else if (product.getProductId() != null) {
// Throw IAE
throw new IllegalArgumentException(MessageFormat.format("product.productId={0} is not expected.", product.getProductId())); //NOI18N
+ } else if (product.getProductCategory() == null) {
+ // Throw NPE
+ throw new NullPointerException("product.productCategory is null"); //NOI18N
+ } else if (product.getProductCategory().getCategoryId() == null) {
+ // Throw NPE
+ throw new NullPointerException("product.productCategory.categoryId is null"); //NOI18N
+ } else if (product.getProductCategory().getCategoryId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("product.productCategory.categoryId={0} is invalid", product.getProductCategory().getCategoryId())); //NOI18N
+ } else if ((product.getProductManfacturer() instanceof BasicData) && (product.getProductManfacturer().getBasicDataId() == null)) {
+ // Throw NPE
+ throw new NullPointerException("product.productManufacturer.basicDataId is null"); //NOI18N
+ } else if ((product.getProductManfacturer() instanceof BasicData) && (product.getProductManfacturer().getBasicDataId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("product.productManufacturer.basicDataId={0} is invalid", product.getProductManfacturer().getBasicDataId())); //NOI18N
} else if (this.isProductCreated(product)) {
// Is already created (by name)
throw new ProductAlreadyAddedException(product);
}
- // Is a category set?
- if (product.getProductCategory()instanceof Category) {
- // Then make it managed
- final Category managedCategory = this.createManaged(product.getProductCategory());
+ // Created a managed instance from product's category
+ final Category managedCategory = this.createManaged(product.getProductCategory());
+
+ // Set it back
+ product.setProductCategory(managedCategory);
+
+ // Is a manufacturer (basic_data entity) set?
+ if (product.getProductManfacturer() instanceof BasicData) {
+ // Get managed instance from it
+ final BasicData managedBasicData = this.createManaged(product.getProductManfacturer());
// Set it back
- product.setProductCategory(managedCategory);
+ product.setProductManfacturer(managedBasicData);
}
// Set created instance