List<CodeCategory> categories = entityDao.getAll(CodeCategory.class);
List<CodeCategory> updated = CollectUtils.newArrayList();
Set<String> names = CollectUtils.newHashSet();
Set<String> duplicatedNames = CollectUtils.newHashSet();
for (CodeCategory category : categories) {
CodeCategory newCategory = populateEntity(CodeCategory.class, category.getId() + "_codeCategory");
if (names.contains(newCategory.getName())) {
duplicatedNames.add(newCategory.getName());
} else {
names.add(newCategory.getName());
updated.add(newCategory);
}
}
CodeCategory newCategory = populateEntity(CodeCategory.class, "newCodeCategory");
if (StringUtils.isNotBlank(newCategory.getName())) {
if (names.contains(newCategory.getName())) {
duplicatedNames.add(newCategory.getName());
} else {
names.add(newCategory.getName());
updated.add(newCategory);
}
}
if (duplicatedNames.size() > 0) {
addFlashErrorNow("dictionary.error.duplicateCategoryName", StrUtils.join(duplicatedNames,","));