Skip to content

Commit fdd95fe

Browse files
Fix duplicate storage access groups
1 parent 507f6fc commit fdd95fe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.cloud.api.query.dao;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.List;
2122

2223
import javax.inject.Inject;
@@ -196,16 +197,24 @@ public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool, boolea
196197
public StoragePoolResponse setStoragePoolResponse(StoragePoolResponse response, StoragePoolJoinVO sp) {
197198
String tag = sp.getTag();
198199
if (tag != null) {
199-
if (response.getTags() != null && response.getTags().length() > 0) {
200-
response.setTags(response.getTags() + "," + tag);
200+
if (response.getTags() != null && !response.getTags().isEmpty()) {
201+
List<String> tagsList = new ArrayList<>(Arrays.asList(response.getTags().split(",")));
202+
if (!tagsList.contains(tag)) {
203+
tagsList.add(tag);
204+
}
205+
response.setTags(String.join(",", tagsList));
201206
} else {
202207
response.setTags(tag);
203208
}
204209
}
205210
String storageAccessGroup = sp.getStorageAccessGroup();
206211
if (storageAccessGroup != null) {
207-
if (response.getStorageAccessGroups() != null && response.getStorageAccessGroups().length() > 0) {
208-
response.setStorageAccessGroups(response.getStorageAccessGroups() + "," + storageAccessGroup);
212+
if (response.getStorageAccessGroups() != null && !response.getStorageAccessGroups().isEmpty()) {
213+
List<String> groupList = new ArrayList<>(Arrays.asList(response.getStorageAccessGroups().split(",")));
214+
if (!groupList.contains(storageAccessGroup)) {
215+
groupList.add(storageAccessGroup);
216+
}
217+
response.setStorageAccessGroups(String.join(",", groupList));
209218
} else {
210219
response.setStorageAccessGroups(storageAccessGroup);
211220
}

0 commit comments

Comments
 (0)