diff --git a/api/src/com/cloud/api/commands/ListGuestOsCategoriesCmd.java b/api/src/com/cloud/api/commands/ListGuestOsCategoriesCmd.java index f94658d07ec..756687c591f 100644 --- a/api/src/com/cloud/api/commands/ListGuestOsCategoriesCmd.java +++ b/api/src/com/cloud/api/commands/ListGuestOsCategoriesCmd.java @@ -45,6 +45,9 @@ public class ListGuestOsCategoriesCmd extends BaseListCmd { @IdentityMapper(entityTableName="guest_os_category") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list Os category by id") private Long id; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list os category by name") + private String name; ///////////////////////////////////////////////////// @@ -55,11 +58,15 @@ public class ListGuestOsCategoriesCmd extends BaseListCmd { return id; } + public String getName() { + return name; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override public String getCommandName() { return s_name; diff --git a/api/src/com/cloud/api/commands/ListGuestOsCmd.java b/api/src/com/cloud/api/commands/ListGuestOsCmd.java index f7e485b3520..55e7ecc3bfc 100644 --- a/api/src/com/cloud/api/commands/ListGuestOsCmd.java +++ b/api/src/com/cloud/api/commands/ListGuestOsCmd.java @@ -49,6 +49,9 @@ public class ListGuestOsCmd extends BaseListCmd { @IdentityMapper(entityTableName="guest_os_category") @Parameter(name=ApiConstants.OS_CATEGORY_ID, type=CommandType.LONG, description="list by Os Category id") private Long osCategoryId; + + @Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="list os by description") + private String description; ///////////////////////////////////////////////////// @@ -63,7 +66,10 @@ public class ListGuestOsCmd extends BaseListCmd { return osCategoryId; } - + public String getDescription() { + return description; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 5443c3b6791..c437c2f4cc5 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1739,19 +1739,25 @@ public class ManagementServerImpl implements ManagementServer { Filter searchFilter = new Filter(GuestOSVO.class, "displayName", true, cmd.getStartIndex(), cmd.getPageSizeVal()); Long id = cmd.getId(); Long osCategoryId = cmd.getOsCategoryId(); + String description = cmd.getDescription(); + String keyword = cmd.getKeyword(); - SearchBuilder sb = _guestOSDao.createSearchBuilder(); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - sb.and("categoryId", sb.entity().getCategoryId(), SearchCriteria.Op.EQ); - - SearchCriteria sc = sb.create(); + SearchCriteria sc = _guestOSDao.createSearchCriteria(); if (id != null) { - sc.setParameters("id", id); + sc.addAnd("id", SearchCriteria.Op.EQ, id); } if (osCategoryId != null) { - sc.setParameters("categoryId", osCategoryId); + sc.addAnd("categoryId", SearchCriteria.Op.EQ, osCategoryId); + } + + if (description != null) { + sc.addAnd("displayName", SearchCriteria.Op.LIKE, "%" + description + "%"); + } + + if (keyword != null) { + sc.addAnd("displayName", SearchCriteria.Op.LIKE, "%" + keyword + "%"); } return _guestOSDao.search(sc, searchFilter); @@ -1761,14 +1767,21 @@ public class ManagementServerImpl implements ManagementServer { public List listGuestOSCategoriesByCriteria(ListGuestOsCategoriesCmd cmd) { Filter searchFilter = new Filter(GuestOSCategoryVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); Long id = cmd.getId(); + String name = cmd.getName(); + String keyword = cmd.getKeyword(); - SearchBuilder sb = _guestOSCategoryDao.createSearchBuilder(); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - - SearchCriteria sc = sb.create(); + SearchCriteria sc = _guestOSCategoryDao.createSearchCriteria(); if (id != null) { - sc.setParameters("id", id); + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + if (name != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + } + + if (keyword != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); } return _guestOSCategoryDao.search(sc, searchFilter);