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.opportunity;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.ofbiz.base.util.UtilMisc;
023: import org.ofbiz.entity.GenericDelegator;
024: import org.ofbiz.entity.GenericEntityException;
025: import org.ofbiz.entity.GenericValue;
026: import org.ofbiz.entity.condition.EntityCondition;
027: import org.ofbiz.entity.condition.EntityConditionList;
028: import org.ofbiz.entity.condition.EntityExpr;
029: import org.ofbiz.entity.condition.EntityOperator;
030: import org.ofbiz.entity.model.DynamicViewEntity;
031: import org.ofbiz.entity.model.ModelKeyMap;
032:
033: import com.sourcetap.sfa.util.EntityHelper;
034:
035: /**
036: * DOCUMENT ME!
037: *
038: */
039: public class OpportunityHelper {
040: public static final String module = OpportunityHelper.class
041: .getName();
042:
043: /**
044: * DOCUMENT ME!
045: *
046: * @param productId
047: * @param delegator
048: *
049: * @return
050: *
051: * @throws GenericEntityException
052: */
053: public static List getProductFeaturesForProduct(String productId,
054: GenericDelegator delegator) throws GenericEntityException {
055:
056: return delegator.findByAnd("ProductFeatureAppl", UtilMisc
057: .toMap("productId", productId), null);
058: }
059:
060: /**
061: * DOCUMENT ME!
062: *
063: * @param productId
064: * @param delegator
065: *
066: * @return
067: *
068: * @throws GenericEntityException
069: */
070: public static List getFeatureTypesForProduct(String productId,
071: GenericDelegator delegator) throws GenericEntityException {
072: List productFeaturesList = getProductFeaturesForProduct(
073: productId, delegator);
074:
075: if ((productFeaturesList != null)
076: && (productFeaturesList.size() == 0)) {
077: return new ArrayList();
078: }
079:
080: GenericValue[] productFeatures = (GenericValue[]) productFeaturesList
081: .toArray(new GenericValue[0]);
082: GenericValue productFeature = null;
083:
084: DynamicViewEntity dve = EntityHelper.createDynamicViewEntity(
085: delegator, "ProductFeatureType");
086: dve.addMemberEntity("ProductFeature", "ProductFeature");
087: dve.addViewLink("ProductFeatureType", "ProductFeature",
088: Boolean.FALSE, UtilMisc
089: .toList(new ModelKeyMap("productFeatureTypeId",
090: "productFeatureTypeId")));
091: dve.addAlias("ProductFeature", "productFeatureId", null, null,
092: null, null, null);
093:
094: List exprList = new ArrayList();
095:
096: String feature = "";
097:
098: for (int i = 0; i < productFeatures.length; i++) {
099: productFeature = productFeatures[i];
100:
101: if (productFeature != null) {
102: feature = productFeature.getString("productFeatureId");
103:
104: if (feature != null) {
105: exprList.add(new EntityExpr("productFeatureId",
106: EntityOperator.EQUALS, feature));
107: }
108: }
109: }
110:
111: EntityCondition condition = new EntityConditionList(exprList,
112: EntityOperator.OR);
113:
114: List productFeatureTypesList = EntityHelper.findByCondition(
115: delegator, dve, condition, null);
116: GenericValue[] productFeatureTypes = (GenericValue[]) productFeatureTypesList
117: .toArray(new GenericValue[0]);
118: GenericValue productFeatureType = null;
119: ArrayList featureTypeList = new ArrayList();
120:
121: for (int i = 0; i < productFeatureTypes.length; i++) {
122: productFeatureType = productFeatureTypes[i];
123:
124: if ((productFeatureType != null)
125: && !featureTypeList.contains(productFeatureType)) {
126: featureTypeList.add(productFeatureType);
127: }
128: }
129:
130: return featureTypeList;
131: }
132:
133: /**
134: * DOCUMENT ME!
135: *
136: * @param productId
137: * @param productFeatureTypeId
138: * @param delegator
139: *
140: * @return
141: *
142: * @throws GenericEntityException
143: */
144: public static String getProductFeatureDescriptionForProduct(
145: String productId, String productFeatureTypeId,
146: GenericDelegator delegator) throws GenericEntityException {
147: /*
148: select
149: product_feature.*
150: from
151: product_feature, product_feature_appl
152: where
153: product_feature_appl.product_id = 'GZ-2644' and
154: product_feature_appl.product_feature_id = product_feature.product_feature_id and
155: product_feature.product_feature_type_id = 'SOFTWARE_FEATURE'
156: */
157: DynamicViewEntity dve = EntityHelper.createDynamicViewEntity(
158: delegator, "ProductFeature");
159: dve.addMemberEntity("ProductFeatureAppl", "ProductFeatureAppl");
160: dve.addViewLink("ProductFeature", "ProductFeatureAppl",
161: Boolean.FALSE, UtilMisc.toList(new ModelKeyMap(
162: "productFeatureId", "productFeatureId")));
163: dve.addAlias("ProductFeatureAppl", "productId", null, null,
164: null, null, null);
165:
166: EntityCondition condition = new EntityConditionList(UtilMisc
167: .toList(new EntityExpr("productFeatureTypeId",
168: EntityOperator.EQUALS, productFeatureTypeId),
169: new EntityExpr("productId",
170: EntityOperator.EQUALS, productId)),
171: EntityOperator.AND);
172:
173: List pfCol = EntityHelper.findByCondition(delegator, dve,
174: condition, null);
175:
176: GenericValue[] pfGvs = (GenericValue[]) pfCol
177: .toArray(new GenericValue[0]);
178:
179: if ((pfGvs == null) || (pfGvs.length <= 0)) {
180: return "";
181: } else {
182: return pfGvs[0].getString("description");
183: }
184: }
185: }
|