Package com.sourcetap.sfa.party

Source Code of com.sourcetap.sfa.party.PartyIdentifierSelectEP

/*
*
* 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.party;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

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.GenericValue;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.ModelEntity;

import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.ui.UIScreenSectionEntity;
import com.sourcetap.sfa.util.QueryInfo;
import com.sourcetap.sfa.util.UserInfo;


/**
* DOCUMENT ME!
*
*/
public class PartyIdentifierSelectEP extends GenericEventProcessor {
    private static final boolean DEBUG = false;
   
  /**
    * replace the CodeValue and CodeId Maps in the removerKeyMapList and createKeyMapList  with identifierId
    *
    * @param userInfo
    * @param delegator
    * @param primaryModelEntity
    * @param removeKeyMapList
    * @param createKeyMapList
    *
    * @return
    */
  protected int preUpdateSelect(UserInfo userInfo,
     GenericDelegator delegator, ModelEntity primaryModelEntity,
     ArrayList removeKeyMapList, ArrayList createKeyMapList)
  {
    replaceCodeTableMap( removeKeyMapList );
    replaceCodeTableMap( createKeyMapList );
    return STATUS_CONTINUE;
  }
 
  private void replaceCodeTableMap( List keyMapList )
  {
    if ( keyMapList == null )
      return;
    Iterator iter = keyMapList.iterator();
    while (iter.hasNext() )
    {
      Map keyMap = (Map) iter.next();
     
      String codeTypeId = (String) keyMap.get("codeTypeId");
      String codeId = (String) keyMap.get("codeId");
     
      if ( (codeTypeId != null) && ( codeTypeId.length() > 0))
      {
        keyMap.remove("codeTypeId");
        keyMap.remove("codeId");
        keyMap.put("identifierId", codeId);
      }
     
    }
  }
 
  /**
   * Add entity clauses for one related entity.  This will join related tables to the query
   * during a retrieve so query values can be entered that are in related entities.
   * <P>
   * This version overrides the ancestor to handle the AccountIdentifier to Code relationship, which
   * has no relation defined.
   *
   * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
   * @param relationTitle Relation title
   * @param relatedEntityName Name of related entity
   * @param primaryEntityName Name of the primary entity
   * @param primaryME ModelEntity object for the primary entity
   * @param queryInfo critera to be used in search.
   */
  public void addOneRelationClause(GenericDelegator delegator,
    String relationTitle, String relatedAndFields, String relatedEntityName,
    String primaryEntityName, ModelEntity primaryME, boolean isOuterJoin, QueryInfo queryInfo)
    throws GenericEntityException {
     
    if (relatedEntityName.equals("Code")) {
      // Adding entity clauses for the Address entity.  Need to build it manually.
      // Join the address owner ID field
           
      queryInfo.addJoin("PartyIdentifier", "Code",  Boolean.valueOf(isOuterJoin), "identifierId", "codeId");
     
      if ( isOuterJoin )
      {
        queryInfo.addAlias("Code", "codeTypeId", "codeTypeId");
        queryInfo.addAlias("Code", "codeId", "codeId");
        queryInfo.addCondition( new EntityConditionList( UtilMisc.toList( new EntityExpr("codeTypeId", EntityOperator.EQUALS, "IDENTIFIER_TYPE"),
                      new EntityExpr("codeId", EntityOperator.EQUALS, null)), EntityOperator.OR));
      }
      else
        queryInfo.addCondition("Code", "codeTypeId", EntityOperator.EQUALS, "IDENTIFIER_TYPE");

    } else {
      // Use the parent script for all other related entities.
      super.addOneRelationClause(delegator, relationTitle, relatedAndFields,
        relatedEntityName, primaryEntityName, primaryME, isOuterJoin, queryInfo);
    }
  }

  /**
   * DOCUMENT ME!
   *
   * @param mainGV
   * @param relatedSearchClause
   * @param outGVV
   * @param userInfo
   * @param delegator
   *
   * @return
   */
  protected GenericValue retrieveOneRelatedGV(GenericValue mainGV,
    UIScreenSectionEntity relatedSearchClause, Vector outGVV, UserInfo userInfo,
    GenericDelegator delegator) {

    String relationRelEntityName = (String) relatedSearchClause.getEntityName();

    if (relationRelEntityName.equals("Code")) {
      // Special processing for the Code record since it can't be retrieved with a relationship
      // defined in the sfa-config.xml file.

      // Get account ID from the account record.
      String identifierId = mainGV.getString("identifierId");

      GenericValue codeGV = null;

      try {
        codeGV = delegator.findByPrimaryKey("Code", UtilMisc.toMap("codeTypeId", "IDENTIFIER_TYPE", "codeId", identifierId));

        return codeGV;
      } catch (GenericEntityException e) {
        Debug.logError(
          "[retrieveOneRelatedGV] An error occurred while searching for " +
          "the Identifier Code record for the partyIdentifier: " +
          e.getLocalizedMessage(), module);

        return codeGV;
      }
    } else {
      // Retrieve all other related entities the regular way.
      return super.retrieveOneRelatedGV(mainGV, relatedSearchClause,
        outGVV, userInfo, delegator);
    }
  }


}
TOP

Related Classes of com.sourcetap.sfa.party.PartyIdentifierSelectEP

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.