Skip to content

Commit

Permalink
Merge pull request #1236 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
work in progress - support map multiple csv cols to a sobject field
  • Loading branch information
ashitsalesforce authored Aug 26, 2024
2 parents 16f458f + 9a97210 commit cc2fed7
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/main/java/com/salesforce/dataloader/mapping/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -81,7 +83,7 @@ public InvalidMappingException(String msg) {
private HashMap<String, Integer> compositeColSizeMap = new HashMap<String, Integer>();
private HashMap<String, Integer> daoColPositionInCompositeColMap = new HashMap<String, Integer>();
private HashMap<String, String> daoColToCompositeColMap = new HashMap<String, String>();

private HashMap<String, Boolean> fieldTypeIsStringMap = new HashMap<String, Boolean>();
private final CaseInsensitiveMap constants = new CaseInsensitiveMap();

protected final CaseInsensitiveMap map = new CaseInsensitiveMap();
Expand All @@ -106,18 +108,27 @@ protected Mapper(PartnerClient client, Collection<String> 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();
Expand All @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit cc2fed7

Please sign in to comment.