public static void checkAndUpdateFileName(FormRowSet results, Element element, String primaryKeyValue) {
Set<String> existedFileName = new HashSet<String>();
for (int i = 0; i < results.size(); i++) {
FormRow row = results.get(i);
String id = row.getId();
if (id != null && !id.isEmpty()) {
Map<String, String> tempFilePathMap = row.getTempFilePathMap();
if (tempFilePathMap != null && !tempFilePathMap.isEmpty()) {
for (Iterator<String> j = tempFilePathMap.keySet().iterator(); j.hasNext();) {
String fieldId = j.next();
String path = tempFilePathMap.get(fieldId);
if (!path.endsWith(FileManager.THUMBNAIL_EXT)) {
File file = FileManager.getFileByPath(path);
if (file != null) {
String fileName = file.getName();
String uploadPath = getUploadPath(element, id);
String newFileName = validateFileName(fileName, uploadPath, existedFileName);
existedFileName.add(newFileName);
if (row.containsKey(fieldId)) {
row.put(fieldId, newFileName);
}
if (!newFileName.equals(file.getName())) {
String newPath = path.replace(file.getName(), newFileName);