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.party;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.Vector;
024:
025: import org.ofbiz.base.util.Debug;
026: import org.ofbiz.base.util.UtilMisc;
027: import org.ofbiz.entity.GenericDelegator;
028: import org.ofbiz.entity.GenericEntityException;
029: import org.ofbiz.entity.GenericValue;
030: import org.ofbiz.entity.condition.EntityConditionList;
031: import org.ofbiz.entity.condition.EntityExpr;
032: import org.ofbiz.entity.condition.EntityOperator;
033: import org.ofbiz.entity.model.ModelEntity;
034:
035: import com.sourcetap.sfa.event.GenericEventProcessor;
036: import com.sourcetap.sfa.ui.UIScreenSectionEntity;
037: import com.sourcetap.sfa.util.QueryInfo;
038: import com.sourcetap.sfa.util.UserInfo;
039:
040: /**
041: * DOCUMENT ME!
042: *
043: */
044: public class PartyIdentifierSelectEP extends GenericEventProcessor {
045: private static final boolean DEBUG = false;
046:
047: /**
048: * replace the CodeValue and CodeId Maps in the removerKeyMapList and createKeyMapList with identifierId
049: *
050: * @param userInfo
051: * @param delegator
052: * @param primaryModelEntity
053: * @param removeKeyMapList
054: * @param createKeyMapList
055: *
056: * @return
057: */
058: protected int preUpdateSelect(UserInfo userInfo,
059: GenericDelegator delegator, ModelEntity primaryModelEntity,
060: ArrayList removeKeyMapList, ArrayList createKeyMapList) {
061: replaceCodeTableMap(removeKeyMapList);
062: replaceCodeTableMap(createKeyMapList);
063: return STATUS_CONTINUE;
064: }
065:
066: private void replaceCodeTableMap(List keyMapList) {
067: if (keyMapList == null)
068: return;
069: Iterator iter = keyMapList.iterator();
070: while (iter.hasNext()) {
071: Map keyMap = (Map) iter.next();
072:
073: String codeTypeId = (String) keyMap.get("codeTypeId");
074: String codeId = (String) keyMap.get("codeId");
075:
076: if ((codeTypeId != null) && (codeTypeId.length() > 0)) {
077: keyMap.remove("codeTypeId");
078: keyMap.remove("codeId");
079: keyMap.put("identifierId", codeId);
080: }
081:
082: }
083: }
084:
085: /**
086: * Add entity clauses for one related entity. This will join related tables to the query
087: * during a retrieve so query values can be entered that are in related entities.
088: * <P>
089: * This version overrides the ancestor to handle the AccountIdentifier to Code relationship, which
090: * has no relation defined.
091: *
092: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
093: * @param relationTitle Relation title
094: * @param relatedEntityName Name of related entity
095: * @param primaryEntityName Name of the primary entity
096: * @param primaryME ModelEntity object for the primary entity
097: * @param queryInfo critera to be used in search.
098: */
099: public void addOneRelationClause(GenericDelegator delegator,
100: String relationTitle, String relatedAndFields,
101: String relatedEntityName, String primaryEntityName,
102: ModelEntity primaryME, boolean isOuterJoin,
103: QueryInfo queryInfo) throws GenericEntityException {
104:
105: if (relatedEntityName.equals("Code")) {
106: // Adding entity clauses for the Address entity. Need to build it manually.
107: // Join the address owner ID field
108:
109: queryInfo.addJoin("PartyIdentifier", "Code", Boolean
110: .valueOf(isOuterJoin), "identifierId", "codeId");
111:
112: if (isOuterJoin) {
113: queryInfo.addAlias("Code", "codeTypeId", "codeTypeId");
114: queryInfo.addAlias("Code", "codeId", "codeId");
115: queryInfo
116: .addCondition(new EntityConditionList(UtilMisc
117: .toList(new EntityExpr("codeTypeId",
118: EntityOperator.EQUALS,
119: "IDENTIFIER_TYPE"),
120: new EntityExpr("codeId",
121: EntityOperator.EQUALS,
122: null)),
123: EntityOperator.OR));
124: } else
125: queryInfo.addCondition("Code", "codeTypeId",
126: EntityOperator.EQUALS, "IDENTIFIER_TYPE");
127:
128: } else {
129: // Use the parent script for all other related entities.
130: super .addOneRelationClause(delegator, relationTitle,
131: relatedAndFields, relatedEntityName,
132: primaryEntityName, primaryME, isOuterJoin,
133: queryInfo);
134: }
135: }
136:
137: /**
138: * DOCUMENT ME!
139: *
140: * @param mainGV
141: * @param relatedSearchClause
142: * @param outGVV
143: * @param userInfo
144: * @param delegator
145: *
146: * @return
147: */
148: protected GenericValue retrieveOneRelatedGV(GenericValue mainGV,
149: UIScreenSectionEntity relatedSearchClause, Vector outGVV,
150: UserInfo userInfo, GenericDelegator delegator) {
151:
152: String relationRelEntityName = (String) relatedSearchClause
153: .getEntityName();
154:
155: if (relationRelEntityName.equals("Code")) {
156: // Special processing for the Code record since it can't be retrieved with a relationship
157: // defined in the sfa-config.xml file.
158:
159: // Get account ID from the account record.
160: String identifierId = mainGV.getString("identifierId");
161:
162: GenericValue codeGV = null;
163:
164: try {
165: codeGV = delegator.findByPrimaryKey("Code", UtilMisc
166: .toMap("codeTypeId", "IDENTIFIER_TYPE",
167: "codeId", identifierId));
168:
169: return codeGV;
170: } catch (GenericEntityException e) {
171: Debug
172: .logError(
173: "[retrieveOneRelatedGV] An error occurred while searching for "
174: + "the Identifier Code record for the partyIdentifier: "
175: + e.getLocalizedMessage(),
176: module);
177:
178: return codeGV;
179: }
180: } else {
181: // Retrieve all other related entities the regular way.
182: return super.retrieveOneRelatedGV(mainGV,
183: relatedSearchClause, outGVV, userInfo, delegator);
184: }
185: }
186:
187: }
|