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.replication;
018:
019: import java.util.HashMap;
020: import java.util.List;
021:
022: import org.ofbiz.base.util.Debug;
023: import org.ofbiz.entity.GenericDelegator;
024: import org.ofbiz.entity.GenericPK;
025: import org.ofbiz.entity.GenericValue;
026:
027: import com.sourcetap.sfa.address.AddressHelper;
028: import com.sourcetap.sfa.security.EntityAccessHelper;
029:
030: /**
031: * This class is used for replication of the Code entity. <P>
032: *
033: * @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
034: */
035: public class AccountReplicator extends EntityReplicator {
036: public static final String module = AccountReplicator.class
037: .getName();
038:
039: /**
040: * Populate the related entity map vector. This method is called from the constructors
041: * to allow the related entities to be specified before replication begins.
042: *
043: * @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
044: */
045: public void populateRelatedEntityMapVector() {
046: // Add related entity maps for all entities to be replicated for each
047: // replicated account.
048:
049: addRelatedEntityMap("", "AccountFile", null, false, false,
050: "com.sourcetap.sfa.replication.FileReplicator");
051:
052: addRelatedEntityMap("", "Address", new HashMap(), false, false,
053: "");
054:
055: addRelatedEntityMap("", "Contact", new HashMap(), false, false,
056: "com.sourcetap.sfa.replication.ContactReplicator");
057:
058: addRelatedEntityMap("", "Activity", new HashMap(), false,
059: false,
060: "com.sourcetap.sfa.replication.ActivityReplicator");
061:
062: addRelatedEntityMap("", "Deal", new HashMap(), false, false,
063: "com.sourcetap.sfa.replication.DealReplicator");
064:
065: addRelatedEntityMap("", "EntityAccess", new HashMap(), false,
066: false,
067: "com.sourcetap.sfa.replication.EntityAccessReplicator");
068:
069: addRelatedEntityMap("", "Forecast", new HashMap(), false,
070: false, "");
071:
072: addRelatedEntityMap("", "Party", new HashMap(), false, false,
073: "");
074:
075: addRelatedEntityMap("", "Role", new HashMap(), false, false, "");
076:
077: addRelatedEntityMap("", "Url", new HashMap(), false, false, "");
078:
079: return;
080: }
081:
082: /**
083: * This method finds all instances of an entity related to the main entity.
084: *
085: * This method overrides the ancestor to filter out instances for the SFA application.
086: *
087: * @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
088: *
089: * @param mainInstance Main entity instance for which related entities will be replicated
090: * @param relationTitle Relation title to be used by the entity engine to find related
091: * entity instances
092: * @param relatedEntityName Name of the related entity to be replicated
093: * @param filterMap HashMap containing additional filter values to be used by the entity
094: * engine when finding related entity instances
095: *
096: * @return List of generic values related to the main entity instance
097: */
098: protected List findOneRelated(GenericDelegator delegator,
099: GenericValue mainInstance, String relationTitle,
100: String relatedEntityName, HashMap filterMap, boolean findAll) {
101:
102: if (delegator == null) {
103: Debug.logError("[findOneRelated] Delegator is required.",
104: module);
105:
106: return null;
107: }
108:
109: if (userInfo == null) {
110: Debug.logError(
111: "[findOneRelated] User info object is required.",
112: module);
113:
114: return null;
115: }
116:
117: GenericPK entityPK = null;
118: String entityKeyString = null;
119:
120: List relatedGVL = null;
121:
122: if (relatedEntityName.equals("EntityAccess")) {
123: // Special processing for EntityAccess entity.
124: return EntityAccessHelper.findRelated(getUserInfo(),
125: delegator, mainInstance, relationTitle);
126: } else if (relatedEntityName.equals("Address")) {
127: // Special processing for Address entity.
128: return AddressHelper.findRelated(getUserInfo(), delegator,
129: mainInstance, relationTitle);
130: } else {
131: // Default processing for all other entities.
132: return super.findOneRelated(delegator, mainInstance,
133: relationTitle, relatedEntityName, filterMap,
134: findAll);
135: }
136: }
137: }
|