mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-20 06:00:44 +00:00
CE-1955 Add support for value-mapping on wide-mode associated fields
This commit is contained in:
@ -106,8 +106,13 @@ public class BulkInsertPrepareValueMappingStep implements BackendStep
|
||||
|
||||
runBackendStepInput.addValue("valueMappingFieldIndex", valueMappingFieldIndex);
|
||||
|
||||
String fullFieldName = fieldNamesToDoValueMapping.get(valueMappingFieldIndex);
|
||||
TableAndField tableAndField = getTableAndField(runBackendStepInput.getValueString("tableName"), fullFieldName);
|
||||
String fullFieldName = fieldNamesToDoValueMapping.get(valueMappingFieldIndex);
|
||||
String fieldNameWithoutWideSuffix = fullFieldName;
|
||||
if(fieldNameWithoutWideSuffix.contains(","))
|
||||
{
|
||||
fieldNameWithoutWideSuffix = fieldNameWithoutWideSuffix.replaceFirst(",.*", "");
|
||||
}
|
||||
TableAndField tableAndField = getTableAndField(runBackendStepInput.getValueString("tableName"), fieldNameWithoutWideSuffix);
|
||||
|
||||
runBackendStepInput.addValue("valueMappingField", new QFrontendFieldMetaData(tableAndField.field()));
|
||||
runBackendStepInput.addValue("valueMappingFullFieldName", fullFieldName);
|
||||
@ -213,6 +218,17 @@ public class BulkInsertPrepareValueMappingStep implements BackendStep
|
||||
StorageInput storageInput = BulkInsertStepUtils.getStorageInputForTheFile(runBackendStepInput);
|
||||
BulkInsertMapping bulkInsertMapping = (BulkInsertMapping) runBackendStepInput.getValue("bulkInsertMapping");
|
||||
|
||||
List<Integer> wideAssociationIndexes = null;
|
||||
if(fullFieldName.contains(","))
|
||||
{
|
||||
wideAssociationIndexes = new ArrayList<>();
|
||||
String indexes = fullFieldName.substring(fullFieldName.lastIndexOf(",") + 1);
|
||||
for(String index : indexes.split("\\."))
|
||||
{
|
||||
wideAssociationIndexes.add(Integer.parseInt(index));
|
||||
}
|
||||
}
|
||||
|
||||
String associationNameChain = null;
|
||||
if(fullFieldName.contains("."))
|
||||
{
|
||||
@ -227,7 +243,7 @@ public class BulkInsertPrepareValueMappingStep implements BackendStep
|
||||
{
|
||||
Set<String> values = new LinkedHashSet<>();
|
||||
BulkLoadFileRow headerRow = bulkInsertMapping.getHasHeaderRow() ? fileToRowsInterface.next() : null;
|
||||
Map<String, Integer> fieldIndexes = bulkInsertMapping.getFieldIndexes(table, associationNameChain, headerRow);
|
||||
Map<String, Integer> fieldIndexes = bulkInsertMapping.getFieldIndexes(table, associationNameChain, headerRow, wideAssociationIndexes);
|
||||
int index = fieldIndexes.get(field.getName());
|
||||
|
||||
while(fileToRowsInterface.hasNext())
|
||||
|
@ -94,12 +94,19 @@ public class BulkLoadValueMapper
|
||||
QFieldMetaData field = table.getField(valueEntry.getKey());
|
||||
Serializable value = valueEntry.getValue();
|
||||
|
||||
String fieldNamePlusWideIndex = field.getName();
|
||||
if(record.getBackendDetail("wideAssociationIndexes") != null)
|
||||
{
|
||||
ArrayList<Integer> indexes = (ArrayList<Integer>) record.getBackendDetail("wideAssociationIndexes");
|
||||
fieldNamePlusWideIndex += "," + StringUtils.join(",", indexes);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// value mappin' //
|
||||
///////////////////
|
||||
if(mappingForTable.containsKey(field.getName()) && value != null)
|
||||
if(mappingForTable.containsKey(fieldNamePlusWideIndex) && value != null)
|
||||
{
|
||||
Serializable mappedValue = mappingForTable.get(field.getName()).get(ValueUtils.getValueAsString(value));
|
||||
Serializable mappedValue = mappingForTable.get(fieldNamePlusWideIndex).get(ValueUtils.getValueAsString(value));
|
||||
if(mappedValue != null)
|
||||
{
|
||||
value = mappedValue;
|
||||
|
@ -28,6 +28,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
@ -185,6 +186,15 @@ public class WideRowsToRecordWithExplicitFieldNameSuffixIndexBasedMapping implem
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// stash the wide-association indexes in records, so that in the value mapper, we know if if this is, e.g., ,1, or ,2.3, for value-mapping //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if(CollectionUtils.nullSafeHasContents(wideAssociationIndexes))
|
||||
{
|
||||
ArrayList<Integer> indexesArrayList = CollectionUtils.useOrWrap(wideAssociationIndexes, new TypeToken<>() {});
|
||||
record.addBackendDetail("wideAssociationIndexes", indexesArrayList);
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user