bug 7907: introduced "exactMatch" flag for listAccounts command (not required, default to "false" if not specified). If it's set to "true", we do exact search by accountName

status 7907: resolved fixed
This commit is contained in:
alena 2011-02-10 15:07:38 -08:00
parent 642efb0274
commit 81afd13f24
4 changed files with 35 additions and 11 deletions

View File

@ -1645,9 +1645,10 @@ public interface ManagementServer {
* Searches for accounts by the specified search criteria
* Can search by: "id", "name", "domainid", "type"
* @param c
* @param exactMatch TODO
* @return List of Accounts
*/
List<AccountVO> searchForAccounts(Criteria c);
List<AccountVO> searchForAccounts(Criteria c, boolean exactMatch);
/**

View File

@ -398,7 +398,8 @@ public abstract class BaseCmd {
SCOPE("scope", BaseCmd.TYPE_STRING, "scope"),
SUM_ACROSS_ZONE("sumacrosszone", BaseCmd.TYPE_BOOLEAN, "sumAcrossZone"),
EXCEPTION("exception", BaseCmd.TYPE_STRING, "excetpion"),
HOST_TAGS("hosttags", BaseCmd.TYPE_STRING, "hostTags");
HOST_TAGS("hosttags", BaseCmd.TYPE_STRING, "hostTags"),
EXACT_MATCH("exactmatch", BaseCmd.TYPE_BOOLEAN, "exactMatch");
private final String _name;
private final short _dataType;

View File

@ -53,7 +53,8 @@ public class ListAccountsCmd extends BaseCmd{
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.EXACT_MATCH, Boolean.FALSE));
}
public String getName() {
@ -74,8 +75,10 @@ public class ListAccountsCmd extends BaseCmd{
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
boolean isAdmin = false;
Long accountId = null;
boolean isAdmin = false;
boolean doExactSearch = false;
Long accountId = null;
Boolean exactMatch = (Boolean)params.get(BaseCmd.Properties.EXACT_MATCH.getName());
String accountName = null;
@ -93,6 +96,10 @@ public class ListAccountsCmd extends BaseCmd{
} else {
accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
accountId = account.getId();
}
if (exactMatch != null) {
doExactSearch = exactMatch;
}
Long startIndex = Long.valueOf(0);
@ -119,7 +126,7 @@ public class ListAccountsCmd extends BaseCmd{
c.addCriteria(Criteria.ID, accountId);
}
List<AccountVO> accounts = getManagementServer().searchForAccounts(c);
List<AccountVO> accounts = getManagementServer().searchForAccounts(c, doExactSearch);
List<Pair<String, Object>> accountTags = new ArrayList<Pair<String, Object>>();
Object[] aTag = new Object[accounts.size()];

View File

@ -4330,7 +4330,7 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public List<AccountVO> searchForAccounts(Criteria c) {
public List<AccountVO> searchForAccounts(Criteria c, boolean exactMatch) {
Filter searchFilter = new Filter(AccountVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
Object id = c.getCriteria(Criteria.ID);
@ -4342,7 +4342,12 @@ public class ManagementServerImpl implements ManagementServer {
Object keyword = c.getCriteria(Criteria.KEYWORD);
SearchBuilder<AccountVO> sb = _accountDao.createSearchBuilder();
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.LIKE);
if (exactMatch) {
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.EQ);
} else {
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.LIKE);
}
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("nid", sb.entity().getId(), SearchCriteria.Op.NEQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
@ -4359,14 +4364,24 @@ public class ManagementServerImpl implements ManagementServer {
SearchCriteria sc = sb.create();
if (keyword != null) {
SearchCriteria ssc = _accountDao.createSearchCriteria();
ssc.addOr("accountName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
if (exactMatch) {
ssc.addOr("accountName", SearchCriteria.Op.EQ, keyword);
} else {
ssc.addOr("accountName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
}
ssc.addOr("state", SearchCriteria.Op.EQ, keyword);
sc.addAnd("accountName", SearchCriteria.Op.SC, ssc);
}
if (accountname != null) {
sc.setParameters("accountName", "%" + accountname + "%");
if (exactMatch) {
sc.setParameters("accountName", accountname);
} else {
sc.setParameters("accountName", "%" + accountname + "%");
}
}
if (id != null) {