From e62062f024397b00e7f974b5c101a21a95ed7afd Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 10 Feb 2023 13:39:23 +0100 Subject: [PATCH] server: fix exception while list users with keyword (#7169) --- .../java/com/cloud/api/query/QueryManagerImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index d5ce58b6c88..560f62ad917 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -132,6 +132,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -531,7 +532,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q Object type = null; String accountName = null; Object state = null; - Object keyword = null; + String keyword = null; Pair, Integer> result = getUserListInternal(caller, permittedAccounts, listAll, id, username, type, accountName, state, keyword, domainId, recursive, null); @@ -560,7 +561,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q Object type = cmd.getAccountType(); String accountName = cmd.getAccountName(); Object state = cmd.getState(); - Object keyword = cmd.getKeyword(); + String keyword = cmd.getKeyword(); Long domainId = cmd.getDomainId(); boolean recursive = cmd.isRecursive(); @@ -573,7 +574,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q } private Pair, Integer> getUserListInternal(Account caller, List permittedAccounts, boolean listAll, Long id, Object username, Object type, - String accountName, Object state, Object keyword, Long domainId, boolean recursive, Filter searchFilter) { + String accountName, Object state, String keyword, Long domainId, boolean recursive, Filter searchFilter) { Ternary domainIdRecursiveListProject = new Ternary(domainId, recursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); @@ -617,7 +618,9 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q ssc.addOr("email", Op.LIKE, "%" + keyword + "%"); ssc.addOr("state", Op.LIKE, "%" + keyword + "%"); ssc.addOr("accountName", Op.LIKE, "%" + keyword + "%"); - ssc.addOr("accountType", Op.LIKE, "%" + keyword + "%"); + if (EnumUtils.isValidEnum(Account.Type.class, keyword.toUpperCase())) { + ssc.addOr("accountType", Op.EQ, EnumUtils.getEnum(Account.Type.class, keyword.toUpperCase())); + } sc.addAnd("username", Op.SC, ssc); }