/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.product;
import java.util.List;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.DynamicViewEntity;
import org.ofbiz.entity.model.ModelKeyMap;
import com.sourcetap.sfa.util.EntityHelper;
import com.sourcetap.sfa.util.UserInfo;
/**
* DOCUMENT ME!
*
*/
public class ProductHelper {
public static final String module = ProductHelper.class.getName();
/**
* DOCUMENT ME!
*
* @param delegator
* @param userInfo
*
* @return
*
* @throws GenericEntityException
*/
public static List getProducts(GenericDelegator delegator, UserInfo userInfo)
throws GenericEntityException {
if (delegator == null) {
Debug.logError("[getProducts] Delegator is required.", module);
return null;
}
if (userInfo == null) {
Debug.logError("[getProducts] User info object is required.", module);
return null;
}
// select X from product p, productAttribute pa where p.productId = pa.productId
// and pa.attrName = "OWNER" and pa.attrValue = "<accountId>
DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "Product");
dve.addMemberEntity("ProductAttribute", "ProductAttribute");
dve.addViewLink("Product", "ProductAttribute", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("productId", "productId")));
dve.addAlias("ProductAttribute", "attrName", null, null, null, null, null);
dve.addAlias("ProductAttribute", "attrValue", null, null, null, null, null);
EntityCondition condition = new EntityConditionList(UtilMisc.toList(
new EntityExpr("attrName", EntityOperator.EQUALS, "OWNER"),
new EntityExpr("attrValue", EntityOperator.EQUALS, userInfo.getAccountId())),
EntityOperator.AND);
return EntityHelper.findByCondition( delegator, dve, condition, null );
}
/**
* DOCUMENT ME!
*
* @param delegator
* @param userInfo
*
* @return
*
* @throws GenericEntityException
*/
public static List getProductCategories(GenericDelegator delegator,
UserInfo userInfo) throws GenericEntityException {
if (delegator == null) {
Debug.logError("[getProductCategories] Delegator is required.", module);
return null;
}
if (userInfo == null) {
Debug.logError(
"[getProductCategories] User info object is required.", module);
return null;
}
// select X from productCategory pc, productCategoryAttribute pca where pc.productCategoryId = pca.productCategoryId
// and pca.attrName = "OWNER" and pca.attrVal = <accountId>
DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "ProductCategory");
dve.addMemberEntity("ProductCategoryAttribute", "ProductCategoryAttribute");
dve.addViewLink("ProductCategory", "ProductCategoryAttribute", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("productCategoryId", "productCategoryId")));
dve.addAlias("ProductCategoryAttribute", "attrName", null, null, null, null, null);
dve.addAlias("ProductCategoryAttribute", "attrValue", null, null, null, null, null);
EntityCondition condition = new EntityConditionList(UtilMisc.toList(
new EntityExpr("attrName", EntityOperator.EQUALS, "OWNER"),
new EntityExpr("attrValue", EntityOperator.EQUALS, userInfo.getAccountId())),
EntityOperator.AND);
return EntityHelper.findByCondition( delegator, dve, condition, null );
}
}