001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.product;
018:
019: import java.util.List;
020:
021: import org.ofbiz.base.util.Debug;
022: import org.ofbiz.base.util.UtilMisc;
023: import org.ofbiz.entity.GenericDelegator;
024: import org.ofbiz.entity.GenericEntityException;
025: import org.ofbiz.entity.condition.EntityCondition;
026: import org.ofbiz.entity.condition.EntityConditionList;
027: import org.ofbiz.entity.condition.EntityExpr;
028: import org.ofbiz.entity.condition.EntityOperator;
029: import org.ofbiz.entity.model.DynamicViewEntity;
030: import org.ofbiz.entity.model.ModelKeyMap;
031:
032: import com.sourcetap.sfa.util.EntityHelper;
033: import com.sourcetap.sfa.util.UserInfo;
034:
035: /**
036: * DOCUMENT ME!
037: *
038: */
039: public class ProductHelper {
040: public static final String module = ProductHelper.class.getName();
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @param delegator
046: * @param userInfo
047: *
048: * @return
049: *
050: * @throws GenericEntityException
051: */
052: public static List getProducts(GenericDelegator delegator,
053: UserInfo userInfo) throws GenericEntityException {
054: if (delegator == null) {
055: Debug.logError("[getProducts] Delegator is required.",
056: module);
057:
058: return null;
059: }
060:
061: if (userInfo == null) {
062: Debug.logError(
063: "[getProducts] User info object is required.",
064: module);
065:
066: return null;
067: }
068:
069: // select X from product p, productAttribute pa where p.productId = pa.productId
070: // and pa.attrName = "OWNER" and pa.attrValue = "<accountId>
071: DynamicViewEntity dve = EntityHelper.createDynamicViewEntity(
072: delegator, "Product");
073: dve.addMemberEntity("ProductAttribute", "ProductAttribute");
074: dve.addViewLink("Product", "ProductAttribute", Boolean.FALSE,
075: UtilMisc.toList(new ModelKeyMap("productId",
076: "productId")));
077: dve.addAlias("ProductAttribute", "attrName", null, null, null,
078: null, null);
079: dve.addAlias("ProductAttribute", "attrValue", null, null, null,
080: null, null);
081:
082: EntityCondition condition = new EntityConditionList(UtilMisc
083: .toList(new EntityExpr("attrName",
084: EntityOperator.EQUALS, "OWNER"),
085: new EntityExpr("attrValue",
086: EntityOperator.EQUALS, userInfo
087: .getAccountId())),
088: EntityOperator.AND);
089:
090: return EntityHelper.findByCondition(delegator, dve, condition,
091: null);
092: }
093:
094: /**
095: * DOCUMENT ME!
096: *
097: * @param delegator
098: * @param userInfo
099: *
100: * @return
101: *
102: * @throws GenericEntityException
103: */
104: public static List getProductCategories(GenericDelegator delegator,
105: UserInfo userInfo) throws GenericEntityException {
106: if (delegator == null) {
107: Debug.logError(
108: "[getProductCategories] Delegator is required.",
109: module);
110:
111: return null;
112: }
113:
114: if (userInfo == null) {
115: Debug
116: .logError(
117: "[getProductCategories] User info object is required.",
118: module);
119:
120: return null;
121: }
122:
123: // select X from productCategory pc, productCategoryAttribute pca where pc.productCategoryId = pca.productCategoryId
124: // and pca.attrName = "OWNER" and pca.attrVal = <accountId>
125: DynamicViewEntity dve = EntityHelper.createDynamicViewEntity(
126: delegator, "ProductCategory");
127: dve.addMemberEntity("ProductCategoryAttribute",
128: "ProductCategoryAttribute");
129: dve.addViewLink("ProductCategory", "ProductCategoryAttribute",
130: Boolean.FALSE, UtilMisc.toList(new ModelKeyMap(
131: "productCategoryId", "productCategoryId")));
132: dve.addAlias("ProductCategoryAttribute", "attrName", null,
133: null, null, null, null);
134: dve.addAlias("ProductCategoryAttribute", "attrValue", null,
135: null, null, null, null);
136:
137: EntityCondition condition = new EntityConditionList(UtilMisc
138: .toList(new EntityExpr("attrName",
139: EntityOperator.EQUALS, "OWNER"),
140: new EntityExpr("attrValue",
141: EntityOperator.EQUALS, userInfo
142: .getAccountId())),
143: EntityOperator.AND);
144:
145: return EntityHelper.findByCondition(delegator, dve, condition,
146: null);
147: }
148: }
|