Skip to content

Commit 7ba3779

Browse files
add keyword to filter
1 parent 4c3d589 commit 7ba3779

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface QuotaTariffDao extends GenericDao<QuotaTariffVO, Long> {
2828

2929
Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, Long startIndex, Long pageSize);
3030

31-
Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize);
31+
Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize, String keyword);
3232

3333
QuotaTariffVO findByName(String name);
3434

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public QuotaTariffVO addQuotaTariff(final QuotaTariffVO plan) {
6565

6666
@Override
6767
public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, Long startIndex, Long pageSize) {
68-
return listQuotaTariffs(startDate, endDate, usageType, name, uuid, listAll, false, startIndex, pageSize);
68+
return listQuotaTariffs(startDate, endDate, usageType, name, uuid, listAll, false, startIndex, pageSize, null);
6969
}
7070

7171
@Override
72-
public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize) {
73-
SearchCriteria<QuotaTariffVO> searchCriteria = createListQuotaTariffsSearchCriteria(startDate, endDate, usageType, name, uuid, listOnlyRemoved);
72+
public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize, String keyword) {
73+
SearchCriteria<QuotaTariffVO> searchCriteria = createListQuotaTariffsSearchCriteria(startDate, endDate, usageType, name, uuid, listOnlyRemoved, keyword);
7474

7575
Filter sorter = new Filter(QuotaTariffVO.class, "usageType", false, startIndex, pageSize);
7676
sorter.addOrderBy(QuotaTariffVO.class, "effectiveOn", false);
@@ -79,7 +79,7 @@ public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date
7979
return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<Pair<List<QuotaTariffVO>, Integer>>) status -> searchAndCount(searchCriteria, sorter, listAll));
8080
}
8181

82-
protected SearchCriteria<QuotaTariffVO> createListQuotaTariffsSearchCriteria(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listOnlyRemoved) {
82+
protected SearchCriteria<QuotaTariffVO> createListQuotaTariffsSearchCriteria(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listOnlyRemoved, String keyword) {
8383
SearchCriteria<QuotaTariffVO> searchCriteria = createListQuotaTariffsSearchBuilder(listOnlyRemoved).create();
8484

8585
searchCriteria.setParametersIfNotNull("startDate", startDate);
@@ -88,6 +88,10 @@ protected SearchCriteria<QuotaTariffVO> createListQuotaTariffsSearchCriteria(Dat
8888
searchCriteria.setParametersIfNotNull("name", name);
8989
searchCriteria.setParametersIfNotNull("uuid", uuid);
9090

91+
if (keyword != null) {
92+
searchCriteria.setParameters("nameLike", "%" + keyword + "%");
93+
}
94+
9195
return searchCriteria;
9296
}
9397

@@ -99,6 +103,7 @@ protected SearchBuilder<QuotaTariffVO> createListQuotaTariffsSearchBuilder(boole
99103
searchBuilder.and("usageType", searchBuilder.entity().getUsageType(), SearchCriteria.Op.EQ);
100104
searchBuilder.and("name", searchBuilder.entity().getName(), SearchCriteria.Op.EQ);
101105
searchBuilder.and("uuid", searchBuilder.entity().getUuid(), SearchCriteria.Op.EQ);
106+
searchBuilder.and("nameLike", searchBuilder.entity().getName(), SearchCriteria.Op.LIKE);
102107

103108
if (listOnlyRemoved) {
104109
searchBuilder.and("removed", searchBuilder.entity().getRemoved(), SearchCriteria.Op.NNULL);

plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,12 @@ public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffPlans(final QuotaTariff
413413
Long pageSize = cmd.getPageSizeVal();
414414
String uuid = cmd.getId();
415415
boolean listOnlyRemoved = cmd.isListOnlyRemoved();
416+
String keyword = cmd.getKeyword();
416417

417418
logger.debug("Listing quota tariffs for parameters [{}].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(cmd, "effectiveDate",
418-
"endDate", "listAll", "name", "page", "pageSize", "usageType", "uuid", "listOnlyRemoved"));
419+
"endDate", "listAll", "name", "page", "pageSize", "usageType", "uuid", "listOnlyRemoved", "keyword"));
419420

420-
return _quotaTariffDao.listQuotaTariffs(startDate, endDate, usageType, name, uuid, listAll, listOnlyRemoved, startIndex, pageSize);
421+
return _quotaTariffDao.listQuotaTariffs(startDate, endDate, usageType, name, uuid, listAll, listOnlyRemoved, startIndex, pageSize, keyword);
421422
}
422423

423424
@Override

0 commit comments

Comments
 (0)