From 9a97210209b4f64e471da3e639cc535e329f6b18 Mon Sep 17 00:00:00 2001 From: ashitsalesforce Date: Sun, 25 Aug 2024 22:00:39 -0700 Subject: [PATCH] work in progress - support map multiple csv cols to a sobject field merge multiple CSV fields only if sobject fields they are mapped to are of string type. Map the first csv field in the mapping list otherwise. --- .../salesforce/dataloader/mapping/Mapper.java | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/salesforce/dataloader/mapping/Mapper.java b/src/main/java/com/salesforce/dataloader/mapping/Mapper.java index 1017a371..4a944d5a 100644 --- a/src/main/java/com/salesforce/dataloader/mapping/Mapper.java +++ b/src/main/java/com/salesforce/dataloader/mapping/Mapper.java @@ -39,6 +39,8 @@ import java.util.StringTokenizer; import com.sforce.soap.partner.Field; +import com.sforce.soap.partner.FieldType; + import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -81,7 +83,7 @@ public InvalidMappingException(String msg) { private HashMap compositeColSizeMap = new HashMap(); private HashMap daoColPositionInCompositeColMap = new HashMap(); private HashMap daoColToCompositeColMap = new HashMap(); - + private HashMap fieldTypeIsStringMap = new HashMap(); private final CaseInsensitiveMap constants = new CaseInsensitiveMap(); protected final CaseInsensitiveMap map = new CaseInsensitiveMap(); @@ -106,18 +108,27 @@ protected Mapper(PartnerClient client, Collection columnNames, Field[] f } if (fields != null) { for (Field field : fields) { + boolean isStringType = true; this.fields.add(field.getName()); + FieldType fieldType = field.getType(); + if (fieldType == FieldType.string + || fieldType == FieldType.textarea) { + isStringType = true; + } else { + isStringType = false; + } + this.fieldTypeIsStringMap.put(field.getName(), isStringType); } } this.mappingFileName = mappingFileName; putPropertyFileMappings(mappingFileName); } - public final void putMapping(String src, String dest) { - String compositeDaoColName = getCompositeDaoColName(src); + public final void putMapping(String src, String destList) { + String compositeDaoColName = getCompositeDaoColName(src, destList); // destination can be multiple field names for upload operations - StringTokenizer st = new StringTokenizer(dest, AppUtil.COMMA); + StringTokenizer st = new StringTokenizer(destList, AppUtil.COMMA); String originalDestList = null; while(st.hasMoreElements()) { String v = st.nextToken(); @@ -132,10 +143,22 @@ public final void putMapping(String src, String dest) { this.map.put(compositeDaoColName, originalDestList); } - private String getCompositeDaoColName(String mappingSrcStr) { + private String getCompositeDaoColName(String mappingSrcStr, String destFieldList) { + boolean isDestinationListStringOnly = true; + StringTokenizer st = new StringTokenizer(destFieldList, AppUtil.COMMA); + while(st.hasMoreElements()) { + String destFieldName = st.nextToken(); + destFieldName = destFieldName.trim(); + Boolean destFieldTypeIsString = this.fieldTypeIsStringMap.get(destFieldName); + if (destFieldTypeIsString == null || !destFieldTypeIsString) { + isDestinationListStringOnly = false; + break; + } + } + String compositeCol = null; int daoColCount = 0; - StringTokenizer st = new StringTokenizer(mappingSrcStr, AppUtil.COMMA); + st = new StringTokenizer(mappingSrcStr, AppUtil.COMMA); while(st.hasMoreElements()) { String mappingSrcCol = st.nextToken(); mappingSrcCol = mappingSrcCol.trim(); @@ -147,6 +170,11 @@ private String getCompositeDaoColName(String mappingSrcStr) { } getDaoColPositionInCompositeColMap().put(daoCol, daoColCount); daoColCount++; + if (!isDestinationListStringOnly) { + // set up only the first daoCol for mapping if the destination + // field list contains a field whose type is not string + break; + } } if (compositeCol == null) { compositeCol = mappingSrcStr;