|
|
|
@@ -362,15 +362,28 @@ public class DatasetServiceImpl implements DatasetService { |
|
|
|
|
|
|
|
|
|
|
|
public void checkDeclaredName(Dataset insert) throws Exception { |
|
|
|
Dataset dataset = datasetDao.findByName(insert.getName()); |
|
|
|
if (dataset != null) { |
|
|
|
Dataset existingDataset = datasetDao.findByName(insert.getName()); |
|
|
|
if (existingDataset != null) { |
|
|
|
// Check if the found dataset is not the same as the one being inserted |
|
|
|
// This is important if you are using this method for both insert and update operations |
|
|
|
// You may need an identifier check here, e.g., if 'insert' has an ID and it's the same as 'existingDataset' |
|
|
|
if (insert.getId() != null && insert.getId().equals(existingDataset.getId())) { |
|
|
|
// This is the same dataset, no duplicate name issue for update operation |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Now we know there's another dataset with the same name |
|
|
|
Field[] fields = Dataset.class.getDeclaredFields(); |
|
|
|
for (Field field : fields) { |
|
|
|
if (field.isAnnotationPresent(CheckDuplicate.class)) { |
|
|
|
field.setAccessible(true); // Make private fields accessible |
|
|
|
|
|
|
|
if ("name".equals(field.getName()) && field.isAnnotationPresent(CheckDuplicate.class)) { |
|
|
|
// If the field is 'name' and is marked with CheckDuplicate annotation |
|
|
|
CheckDuplicate annotation = field.getAnnotation(CheckDuplicate.class); |
|
|
|
throw new Exception(field.getName()+ annotation.message()); |
|
|
|
throw new Exception("重复的数据集名称: " + insert.getName() + ". " + annotation.message()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |