Skip to content

Commit 2d4f646

Browse files
committed
[INLONG-5285][Manager] add a check on the order field
1 parent 879ee14 commit 2d4f646

File tree

10 files changed

+65
-26
lines changed

10 files changed

+65
-26
lines changed

inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/beans/PageRequest.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,34 @@
2626
@ApiModel(value = "Pagination request")
2727
public class PageRequest {
2828

29-
@ApiModelProperty(value = "current page, default 1", required = true, example = "1")
29+
@ApiModelProperty(value = "Current page number, default is 1")
3030
private int pageNum = 1;
3131

32-
@ApiModelProperty(value = "page size, default 10", required = true, example = "10")
32+
@ApiModelProperty(value = "Page size, default is 10")
3333
private int pageSize = 10;
3434

35-
@ApiModelProperty(value = "order field, default create_time", example = "create_time")
35+
@ApiModelProperty(value = "Order field, support create_time and modify_time, default is create_time")
3636
private String orderField = "create_time";
3737

38-
@ApiModelProperty(value = "order type, default desc", example = "desc")
38+
@ApiModelProperty(value = "Order type, only support asc and desc, default is desc")
3939
private String orderType = "desc";
4040

4141
public String getOrderField() {
4242
return orderField;
4343
}
4444

45-
public void setOrderField(String orderField) {
45+
public PageRequest setOrderField(String orderField) {
4646
this.orderField = orderField;
47+
return this;
4748
}
4849

4950
public String getOrderType() {
5051
return orderType;
5152
}
5253

53-
public void setOrderType(String orderType) {
54+
public PageRequest setOrderType(String orderType) {
5455
this.orderType = orderType;
56+
return this;
5557
}
5658

5759
public int getPageNum() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.inlong.manager.common.enums;
19+
20+
import org.apache.inlong.manager.common.beans.PageRequest;
21+
22+
/**
23+
* The order type enumeration.
24+
*/
25+
public enum OrderTypeEnum {
26+
27+
DESC,
28+
29+
ASC;
30+
31+
public static void checkOrderType(PageRequest pageRequest) {
32+
for (OrderTypeEnum value : values()) {
33+
if (value.name().equalsIgnoreCase(pageRequest.getOrderType())) {
34+
pageRequest.setOrderType(value.name().toLowerCase());
35+
return;
36+
}
37+
}
38+
pageRequest.setOrderType(DESC.name().toLowerCase());
39+
}
40+
41+
}

inlong-manager/manager-dao/src/main/resources/mappers/InlongGroupEntityMapper.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,8 @@
155155
</if>
156156
</where>
157157
<choose>
158-
<when test="orderField != null and orderField != '' and orderType = 'desc'">
159-
order by ${orderField} desc
160-
</when>
161-
<when test="orderField != null and orderField != '' and orderType = 'asc'">
162-
order by ${orderField} asc
158+
<when test="orderField != null and orderField != '' and orderType != null and orderType != ''">
159+
order by ${orderField} ${orderType}
163160
</when>
164161
<otherwise>
165162
order by create_time desc

inlong-manager/manager-dao/src/main/resources/mappers/InlongStreamEntityMapper.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,8 @@
263263
</if>
264264
</where>
265265
<choose>
266-
<when test="request.orderField != null and request.orderField != '' and request.orderType = 'desc'">
267-
order by stream.${request.orderField} desc
268-
</when>
269-
<when test="request.orderField != null and request.orderField != '' and request.orderType = 'asc'">
270-
order by stream.${request.orderField} asc
266+
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
267+
order by stream.${request.orderField} ${request.orderType}
271268
</when>
272269
<otherwise>
273270
order by stream.create_time desc

inlong-manager/manager-dao/src/main/resources/mappers/StreamSinkEntityMapper.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,8 @@
109109
</if>
110110
</where>
111111
<choose>
112-
<when test="orderField != null and orderField != '' and orderType = 'desc'">
113-
order by ${request.orderField} desc
114-
</when>
115-
<when test="orderField != null and orderField != '' and orderType = 'asc'">
116-
order by ${request.orderField} asc
112+
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
113+
order by ${request.orderField} ${request.orderType}
117114
</when>
118115
<otherwise>
119116
order by create_time desc

inlong-manager/manager-dao/src/main/resources/mappers/StreamSourceEntityMapper.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,8 @@
127127
</if>
128128
</where>
129129
<choose>
130-
<when test="orderField != null and orderField != '' and orderType = 'desc'">
131-
order by ${request.orderField} desc
132-
</when>
133-
<when test="orderField != null and orderField != '' and orderType = 'asc'">
134-
order by ${request.orderField} asc
130+
<when test="request.orderField != null and request.orderField != '' and request.orderType != null and request.orderType != ''">
131+
order by ${request.orderField} ${request.orderType}
135132
</when>
136133
<otherwise>
137134
order by create_time desc

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/InlongStreamServiceImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2727
import org.apache.inlong.manager.common.enums.GroupStatus;
2828
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
29+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
2930
import org.apache.inlong.manager.common.enums.StreamStatus;
3031
import org.apache.inlong.manager.common.exceptions.BusinessException;
3132
import org.apache.inlong.manager.common.pojo.sink.SinkBriefInfo;
@@ -204,6 +205,7 @@ public PageInfo<InlongStreamBriefInfo> listBrief(InlongStreamPageRequest request
204205

205206
PageHelper.startPage(request.getPageNum(), request.getPageSize());
206207
OrderFieldEnum.checkOrderField(request);
208+
OrderTypeEnum.checkOrderType(request);
207209
Page<InlongStreamEntity> entityPage = (Page<InlongStreamEntity>) streamMapper.selectByCondition(request);
208210
List<InlongStreamBriefInfo> streamList = CommonBeanUtils.copyListProperties(entityPage,
209211
InlongStreamBriefInfo::new);

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
3030
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
31+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
3132
import org.apache.inlong.manager.common.enums.SourceType;
3233
import org.apache.inlong.manager.common.exceptions.BusinessException;
3334
import org.apache.inlong.manager.common.exceptions.WorkflowListenerException;
@@ -178,6 +179,7 @@ public PageInfo<InlongGroupBriefInfo> listBrief(InlongGroupPageRequest request)
178179
}
179180
PageHelper.startPage(request.getPageNum(), request.getPageSize());
180181
OrderFieldEnum.checkOrderField(request);
182+
OrderTypeEnum.checkOrderType(request);
181183
Page<InlongGroupEntity> entityPage = (Page<InlongGroupEntity>) groupMapper.selectByCondition(request);
182184

183185
List<InlongGroupBriefInfo> briefInfos = CommonBeanUtils.copyListProperties(entityPage,

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/StreamSinkServiceImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
3030
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
31+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
3132
import org.apache.inlong.manager.common.enums.SinkStatus;
3233
import org.apache.inlong.manager.common.enums.SinkType;
3334
import org.apache.inlong.manager.common.exceptions.BusinessException;
@@ -185,6 +186,7 @@ public PageInfo<? extends StreamSink> listByCondition(SinkPageRequest request) {
185186

186187
PageHelper.startPage(request.getPageNum(), request.getPageSize());
187188
OrderFieldEnum.checkOrderField(request);
189+
OrderTypeEnum.checkOrderType(request);
188190
List<StreamSinkEntity> entityPage = sinkMapper.selectByCondition(request);
189191
Map<SinkType, Page<StreamSinkEntity>> sinkMap = Maps.newHashMap();
190192
for (StreamSinkEntity streamSink : entityPage) {

inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/source/StreamSourceServiceImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
3030
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
31+
import org.apache.inlong.manager.common.enums.OrderTypeEnum;
3132
import org.apache.inlong.manager.common.enums.SourceStatus;
3233
import org.apache.inlong.manager.common.enums.SourceType;
3334
import org.apache.inlong.manager.common.exceptions.BusinessException;
@@ -173,6 +174,7 @@ public PageInfo<? extends StreamSource> listByCondition(SourcePageRequest reques
173174

174175
PageHelper.startPage(request.getPageNum(), request.getPageSize());
175176
OrderFieldEnum.checkOrderField(request);
177+
OrderTypeEnum.checkOrderType(request);
176178
List<StreamSourceEntity> entityList = sourceMapper.selectByCondition(request);
177179

178180
// Encapsulate the paging query results into the PageInfo object to obtain related paging information

0 commit comments

Comments
 (0)