Skip to content

Commit 91250ad

Browse files
committed
[INLONG-5285][Manager] Support custom query for group, stream, source and sink
1 parent 2bcd555 commit 91250ad

File tree

10 files changed

+115
-4
lines changed

10 files changed

+115
-4
lines changed

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

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ public class PageRequest {
3232
@ApiModelProperty(value = "page size, default 10", required = true, example = "10")
3333
private int pageSize = 10;
3434

35+
@ApiModelProperty(value = "order field, default create_time", example = "create_time")
36+
private String orderField = "create_time";
37+
38+
@ApiModelProperty(value = "order type, default desc", example = "desc")
39+
private String orderType = "desc";
40+
41+
public String getOrderField() {
42+
return orderField;
43+
}
44+
45+
public void setOrderField(String orderField) {
46+
this.orderField = orderField;
47+
}
48+
49+
public String getOrderType() {
50+
return orderType;
51+
}
52+
53+
public void setOrderType(String orderType) {
54+
this.orderType = orderType;
55+
}
56+
3557
public int getPageNum() {
3658
return pageNum;
3759
}
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 field enumeration.
24+
*/
25+
public enum OrderFieldEnum {
26+
27+
CREATE_TIME,
28+
29+
MODIFY_TIME;
30+
31+
public static void checkOrderField(PageRequest pageRequest) {
32+
for (OrderFieldEnum value : values()) {
33+
if (value.name().equalsIgnoreCase(pageRequest.getOrderField())) {
34+
pageRequest.setOrderField(value.name().toLowerCase());
35+
return;
36+
}
37+
}
38+
pageRequest.setOrderField(CREATE_TIME.name().toLowerCase());
39+
}
40+
41+
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,17 @@
154154
</foreach>
155155
</if>
156156
</where>
157-
order by modify_time desc
157+
<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
163+
</when>
164+
<otherwise>
165+
order by create_time desc
166+
</otherwise>
167+
</choose>
158168
</select>
159169
<select id="selectBriefList" parameterType="org.apache.inlong.manager.common.pojo.group.InlongGroupPageRequest"
160170
resultType="org.apache.inlong.manager.common.pojo.group.InlongGroupBriefInfo">

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,17 @@
262262
and stream.status = #{request.status, jdbcType=INTEGER}
263263
</if>
264264
</where>
265-
order by stream.modify_time desc
265+
<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
271+
</when>
272+
<otherwise>
273+
order by stream.create_time desc
274+
</otherwise>
275+
</choose>
266276
</select>
267277
<select id="selectBriefList" resultType="org.apache.inlong.manager.common.pojo.stream.InlongStreamBriefInfo">
268278
select id, inlong_group_id, inlong_stream_id, name, mq_resource, modify_time

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,18 @@
107107
<if test="request.sortConsumerGroup != null and request.sortConsumerGroup != ''">
108108
and sort_consumer_group = #{request.sortConsumerGroup, jdbcType=VARCHAR}
109109
</if>
110-
order by modify_time desc
111110
</where>
111+
<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
117+
</when>
118+
<otherwise>
119+
order by create_time desc
120+
</otherwise>
121+
</choose>
112122
</select>
113123
<select id="selectSummary"
114124
resultType="org.apache.inlong.manager.common.pojo.sink.SinkBriefInfo">

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,18 @@
125125
<if test="request.status != null and request.status != ''">
126126
and status = #{request.status, jdbcType=INTEGER}
127127
</if>
128-
order by modify_time desc
129128
</where>
129+
<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
135+
</when>
136+
<otherwise>
137+
order by create_time desc
138+
</otherwise>
139+
</choose>
130140
</select>
131141
<select id="selectByAgentIp" resultType="org.apache.inlong.manager.dao.entity.StreamSourceEntity">
132142
select

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
@@ -25,6 +25,7 @@
2525
import org.apache.inlong.manager.common.consts.InlongConstants;
2626
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2727
import org.apache.inlong.manager.common.enums.GroupStatus;
28+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
2829
import org.apache.inlong.manager.common.enums.StreamStatus;
2930
import org.apache.inlong.manager.common.exceptions.BusinessException;
3031
import org.apache.inlong.manager.common.pojo.sink.SinkBriefInfo;
@@ -202,6 +203,7 @@ public PageInfo<InlongStreamBriefInfo> listBrief(InlongStreamPageRequest request
202203
LOGGER.debug("begin to list inlong stream page by {}", request);
203204

204205
PageHelper.startPage(request.getPageNum(), request.getPageSize());
206+
OrderFieldEnum.checkOrderField(request);
205207
Page<InlongStreamEntity> entityPage = (Page<InlongStreamEntity>) streamMapper.selectByCondition(request);
206208
List<InlongStreamBriefInfo> streamList = CommonBeanUtils.copyListProperties(entityPage,
207209
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
@@ -27,6 +27,7 @@
2727
import org.apache.inlong.manager.common.consts.InlongConstants;
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
30+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
3031
import org.apache.inlong.manager.common.enums.SourceType;
3132
import org.apache.inlong.manager.common.exceptions.BusinessException;
3233
import org.apache.inlong.manager.common.exceptions.WorkflowListenerException;
@@ -176,6 +177,7 @@ public PageInfo<InlongGroupBriefInfo> listBrief(InlongGroupPageRequest request)
176177
request.setPageSize(MAX_PAGE_SIZE);
177178
}
178179
PageHelper.startPage(request.getPageNum(), request.getPageSize());
180+
OrderFieldEnum.checkOrderField(request);
179181
Page<InlongGroupEntity> entityPage = (Page<InlongGroupEntity>) groupMapper.selectByCondition(request);
180182

181183
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
@@ -27,6 +27,7 @@
2727
import org.apache.inlong.manager.common.consts.InlongConstants;
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
30+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
3031
import org.apache.inlong.manager.common.enums.SinkStatus;
3132
import org.apache.inlong.manager.common.enums.SinkType;
3233
import org.apache.inlong.manager.common.exceptions.BusinessException;
@@ -183,6 +184,7 @@ public PageInfo<? extends StreamSink> listByCondition(SinkPageRequest request) {
183184
Preconditions.checkNotNull(request.getInlongGroupId(), ErrorCodeEnum.GROUP_ID_IS_EMPTY.getMessage());
184185

185186
PageHelper.startPage(request.getPageNum(), request.getPageSize());
187+
OrderFieldEnum.checkOrderField(request);
186188
List<StreamSinkEntity> entityPage = sinkMapper.selectByCondition(request);
187189
Map<SinkType, Page<StreamSinkEntity>> sinkMap = Maps.newHashMap();
188190
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
@@ -27,6 +27,7 @@
2727
import org.apache.inlong.manager.common.consts.InlongConstants;
2828
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
2929
import org.apache.inlong.manager.common.enums.GroupStatus;
30+
import org.apache.inlong.manager.common.enums.OrderFieldEnum;
3031
import org.apache.inlong.manager.common.enums.SourceStatus;
3132
import org.apache.inlong.manager.common.enums.SourceType;
3233
import org.apache.inlong.manager.common.exceptions.BusinessException;
@@ -171,6 +172,7 @@ public PageInfo<? extends StreamSource> listByCondition(SourcePageRequest reques
171172
Preconditions.checkNotNull(request.getInlongGroupId(), ErrorCodeEnum.GROUP_ID_IS_EMPTY.getMessage());
172173

173174
PageHelper.startPage(request.getPageNum(), request.getPageSize());
175+
OrderFieldEnum.checkOrderField(request);
174176
List<StreamSourceEntity> entityList = sourceMapper.selectByCondition(request);
175177

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

0 commit comments

Comments
 (0)