in extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ProfileExportServiceImpl.java [98:141]
public String convertProfileToCSVLine(Profile profile, ExportConfiguration exportConfiguration, Collection<PropertyType> propertiesDef) {
Map<String, String> mapping = (Map<String, String>) exportConfiguration.getProperty("mapping");
String lineToWrite = "";
for (int i = 0; i < mapping.size(); i++) {
String propertyName = mapping.get(String.valueOf(i));
if (propertyName == null) {
LOGGER.error("No index {} found in the provided mapping!", i);
return "";
}
PropertyType propType = RouterUtils.getPropertyTypeById(propertiesDef, propertyName);
Object propertyValue = profile.getProperty(propertyName);
if (propType != null && BooleanUtils.isTrue(propType.isMultivalued())) {
if (propertyValue != null) {
List<String> multiValue = (List<String>) propertyValue;
lineToWrite += StringUtils.isNotBlank(exportConfiguration.getMultiValueDelimiter()) ? exportConfiguration.getMultiValueDelimiter().charAt(0) : "";
int j = 0;
for (String entry : multiValue) {
lineToWrite += entry.replaceAll("\"", "\"\"");
if (j + 1 < multiValue.size()) {
lineToWrite += exportConfiguration.getMultiValueSeparator();
}
j++;
}
lineToWrite += StringUtils.isNotBlank(exportConfiguration.getMultiValueDelimiter()) ? exportConfiguration.getMultiValueDelimiter().charAt(1) : "";
} else {
lineToWrite += "";
}
} else {
if(propertyValue != null) {
propertyValue = propertyValue.toString().replaceAll("\"", "\"\"");
if (StringUtils.contains(propertyValue.toString(), exportConfiguration.getColumnSeparator())) {
propertyValue = "\"" + propertyValue + "\"";
}
lineToWrite += propertyValue.toString();
} else {
lineToWrite += "";
}
}
if (i + 1 < mapping.size()) {
lineToWrite += exportConfiguration.getColumnSeparator();
}
}
return lineToWrite;
}