This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new d9c386eb20 [INLONG-8423][Manager] Manager client support tenant 
operation (#8428)
d9c386eb20 is described below

commit d9c386eb20ef0ac1ce42d68c50e7c6c33fe45efb
Author: castor <[email protected]>
AuthorDate: Thu Jul 6 17:59:49 2023 +0800

    [INLONG-8423][Manager] Manager client support tenant operation (#8428)
    
    Co-authored-by: castorqin <[email protected]>
---
 .../client/api/inner/client/ClientFactory.java     |  4 +
 .../api/inner/client/InlongTenantClient.java       | 89 ++++++++++++++++++++++
 .../api/inner/client/InlongTenantRoleClient.java   | 86 +++++++++++++++++++++
 .../client/api/service/InlongTenantApi.java        | 45 +++++++++++
 .../client/api/service/InlongTenantRoleApi.java}   | 52 +++++--------
 .../manager/service/user/TenantRoleService.java    |  7 +-
 .../service/user/TenantRoleServiceImpl.java        | 11 ++-
 .../service/user/TenantRoleServiceTest.java        |  6 +-
 .../web/controller/InlongTenantRoleController.java |  4 +-
 9 files changed, 261 insertions(+), 43 deletions(-)

diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
index 3b9cbdc3be..3c67f1fa71 100644
--- 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
@@ -53,6 +53,8 @@ public class ClientFactory {
     private final WorkflowEventClient workflowEventClient;
     private final InlongConsumeClient consumeClient;
     private final AuditClient auditClient;
+    private final InlongTenantClient inlongTenantClient;
+    private final InlongTenantRoleClient inlongTenantRoleClient;
 
     public ClientFactory(ClientConfiguration configuration) {
         groupClient = new InlongGroupClient(configuration);
@@ -70,5 +72,7 @@ public class ClientFactory {
         workflowEventClient = new WorkflowEventClient(configuration);
         consumeClient = new InlongConsumeClient(configuration);
         auditClient = new AuditClient(configuration);
+        inlongTenantClient = new InlongTenantClient(configuration);
+        inlongTenantRoleClient = new InlongTenantRoleClient(configuration);
     }
 }
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongTenantClient.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongTenantClient.java
new file mode 100644
index 0000000000..14546cba9e
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongTenantClient.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.inner.client;
+
+import org.apache.inlong.manager.client.api.ClientConfiguration;
+import org.apache.inlong.manager.client.api.service.InlongTenantApi;
+import org.apache.inlong.manager.client.api.util.ClientUtils;
+import org.apache.inlong.manager.pojo.common.PageResult;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.tenant.InlongTenantInfo;
+import org.apache.inlong.manager.pojo.tenant.InlongTenantPageRequest;
+import org.apache.inlong.manager.pojo.tenant.InlongTenantRequest;
+
+/**
+ * Client for {@link InlongTenantApi}.
+ */
+public class InlongTenantClient {
+
+    private final InlongTenantApi inlongTenantApi;
+
+    public InlongTenantClient(ClientConfiguration configuration) {
+        inlongTenantApi = 
ClientUtils.createRetrofit(configuration).create(InlongTenantApi.class);
+    }
+
+    /**
+     * Get inlong tenant by tenant name
+     *
+     * @param name tenant name
+     * @return {@link InlongTenantInfo}
+     */
+    public InlongTenantInfo getTenantByName(String name) {
+        Response<InlongTenantInfo> inlongTenantInfoResponse = 
ClientUtils.executeHttpCall(inlongTenantApi.get(name));
+        ClientUtils.assertRespSuccess(inlongTenantInfoResponse);
+        return inlongTenantInfoResponse.getData();
+    }
+
+    /**
+     * Create inlong tenant
+     *
+     * @param inlongTenantRequest tenant info
+     * @return inlong tenant id
+     */
+    public Integer save(InlongTenantRequest inlongTenantRequest) {
+        Response<Integer> saveInlongTenantResult = ClientUtils.executeHttpCall(
+                inlongTenantApi.createInLongTenant(inlongTenantRequest));
+        ClientUtils.assertRespSuccess(saveInlongTenantResult);
+        return saveInlongTenantResult.getData();
+    }
+
+    /**
+     * Paging query tenant info based on conditions.
+     *
+     * @param inlongTenantPageRequest paging request
+     * @return tenant page list
+     */
+    public PageResult<InlongTenantInfo> 
listByCondition(InlongTenantPageRequest inlongTenantPageRequest) {
+        Response<PageResult<InlongTenantInfo>> pageResultResponse = 
ClientUtils.executeHttpCall(
+                inlongTenantApi.listByCondition(inlongTenantPageRequest));
+        ClientUtils.assertRespSuccess(pageResultResponse);
+        return pageResultResponse.getData();
+    }
+
+    /**
+     * Update one tenant
+     *
+     * @param request tenant request that needs to be modified
+     * @return whether succeed
+     */
+    public Boolean update(InlongTenantRequest request) {
+        Response<Boolean> updateResult = 
ClientUtils.executeHttpCall(inlongTenantApi.update(request));
+        ClientUtils.assertRespSuccess(updateResult);
+        return updateResult.getData();
+    }
+}
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongTenantRoleClient.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongTenantRoleClient.java
new file mode 100644
index 0000000000..2c8b5c46ee
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/InlongTenantRoleClient.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.inner.client;
+
+import org.apache.inlong.manager.client.api.ClientConfiguration;
+import org.apache.inlong.manager.client.api.service.InlongTenantRoleApi;
+import org.apache.inlong.manager.client.api.util.ClientUtils;
+import org.apache.inlong.manager.pojo.common.PageResult;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.user.TenantRoleInfo;
+import org.apache.inlong.manager.pojo.user.TenantRolePageRequest;
+import org.apache.inlong.manager.pojo.user.TenantRoleRequest;
+
+public class InlongTenantRoleClient {
+
+    private final InlongTenantRoleApi inlongTenantRoleApi;
+
+    public InlongTenantRoleClient(ClientConfiguration configuration) {
+        this.inlongTenantRoleApi = 
ClientUtils.createRetrofit(configuration).create(InlongTenantRoleApi.class);
+    }
+
+    /**
+     * List all tenant role by paginating
+     *
+     * @param request tenant page info
+     * @return {@link PageResult}
+     */
+    public PageResult<TenantRoleInfo> listByCondition(TenantRolePageRequest 
request) {
+        Response<PageResult<TenantRoleInfo>> pageInfoResponse = 
ClientUtils.executeHttpCall(
+                inlongTenantRoleApi.listByCondition(request));
+        ClientUtils.assertRespSuccess(pageInfoResponse);
+        return pageInfoResponse.getData();
+    }
+
+    /**
+     * Save  tenant role
+     *
+     * @param record tenant role info
+     * @return tenant id
+     */
+    public int save(TenantRoleRequest record) {
+        Response<Integer> saveResult = 
ClientUtils.executeHttpCall(inlongTenantRoleApi.save(record));
+        ClientUtils.assertRespSuccess(saveResult);
+        return saveResult.getData();
+    }
+
+    /**
+     * Update  tenant role
+     *
+     * @param  record tenant role info
+     * @return true/false
+     */
+    public boolean update(TenantRoleRequest record) {
+        Response<Boolean> updateResult = 
ClientUtils.executeHttpCall(inlongTenantRoleApi.update(record));
+        ClientUtils.assertRespSuccess(updateResult);
+        return updateResult.getData();
+    }
+
+    /**
+     * Get tenant role by id
+     *
+     * @param id tenantRole id
+     * @return {@link TenantRoleInfo}
+     */
+    public TenantRoleInfo get(int id) {
+        Response<TenantRoleInfo> tenantRoleInfoResponse = 
ClientUtils.executeHttpCall(inlongTenantRoleApi.get(id));
+        ClientUtils.assertRespSuccess(tenantRoleInfoResponse);
+        return tenantRoleInfoResponse.getData();
+    }
+
+}
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/InlongTenantApi.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/InlongTenantApi.java
new file mode 100644
index 0000000000..044ceb7ae8
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/InlongTenantApi.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.service;
+
+import org.apache.inlong.manager.pojo.common.PageResult;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.tenant.InlongTenantInfo;
+import org.apache.inlong.manager.pojo.tenant.InlongTenantPageRequest;
+import org.apache.inlong.manager.pojo.tenant.InlongTenantRequest;
+
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
+
+public interface InlongTenantApi {
+
+    @POST("tenant/save")
+    Call<Response<Integer>> createInLongTenant(@Body InlongTenantRequest 
request);
+
+    @POST("tenant/list")
+    Call<Response<PageResult<InlongTenantInfo>>> listByCondition(@Body 
InlongTenantPageRequest request);
+
+    @POST("tenant/update")
+    Call<Response<Boolean>> update(@Body InlongTenantRequest request);
+
+    @POST("tenant/get/{name}")
+    Call<Response<InlongTenantInfo>> get(@Path("name") String name);
+
+}
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/InlongTenantRoleApi.java
similarity index 56%
copy from 
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
copy to 
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/InlongTenantRoleApi.java
index 34b7a3ec9b..7fa1460c32 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/InlongTenantRoleApi.java
@@ -15,41 +15,31 @@
  * limitations under the License.
  */
 
-package org.apache.inlong.manager.service.user;
+package org.apache.inlong.manager.client.api.service;
 
+import org.apache.inlong.manager.pojo.common.PageResult;
+import org.apache.inlong.manager.pojo.common.Response;
 import org.apache.inlong.manager.pojo.user.TenantRoleInfo;
 import org.apache.inlong.manager.pojo.user.TenantRolePageRequest;
 import org.apache.inlong.manager.pojo.user.TenantRoleRequest;
 
-import com.github.pagehelper.PageInfo;
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.GET;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
 
-/**
- * Tenant Role service
- */
-public interface TenantRoleService {
-
-    /**
-     * List all tenant role by paginating
-     */
-    PageInfo<TenantRoleInfo> listByCondition(TenantRolePageRequest request);
-
-    /**
-     * Save one tenant role
-     */
-    int save(TenantRoleRequest record, String operator);
-
-    /**
-     * Update one tanant role
-     */
-    boolean update(TenantRoleRequest record, String operator);
-
-    /**
-     * Get one tenant role by id
-     */
-    TenantRoleInfo get(int id);
-
-    /**
-     * Get one tenant role by name and tenant
-     */
-    TenantRoleInfo getByUsernameAndTenant(String name, String tenant);
+public interface InlongTenantRoleApi {
+
+    @GET("role/tenant/get/{id}")
+    Call<Response<TenantRoleInfo>> get(@Path("id") int id);
+
+    @POST("role/tenant/save")
+    Call<Response<Integer>> save(@Body TenantRoleRequest request);
+
+    @POST("role/tenant/update")
+    Call<Response<Boolean>> update(@Body TenantRoleRequest request);
+
+    @POST("role/tenant/list")
+    Call<Response<PageResult<TenantRoleInfo>>> listByCondition(@Body 
TenantRolePageRequest request);
 }
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
index 34b7a3ec9b..15d8fa429a 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleService.java
@@ -17,12 +17,11 @@
 
 package org.apache.inlong.manager.service.user;
 
+import org.apache.inlong.manager.pojo.common.PageResult;
 import org.apache.inlong.manager.pojo.user.TenantRoleInfo;
 import org.apache.inlong.manager.pojo.user.TenantRolePageRequest;
 import org.apache.inlong.manager.pojo.user.TenantRoleRequest;
 
-import com.github.pagehelper.PageInfo;
-
 /**
  * Tenant Role service
  */
@@ -31,7 +30,7 @@ public interface TenantRoleService {
     /**
      * List all tenant role by paginating
      */
-    PageInfo<TenantRoleInfo> listByCondition(TenantRolePageRequest request);
+    PageResult<TenantRoleInfo> listByCondition(TenantRolePageRequest request);
 
     /**
      * Save one tenant role
@@ -39,7 +38,7 @@ public interface TenantRoleService {
     int save(TenantRoleRequest record, String operator);
 
     /**
-     * Update one tanant role
+     * Update one tenant role
      */
     boolean update(TenantRoleRequest record, String operator);
 
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleServiceImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleServiceImpl.java
index 43bc622509..bf4f6e3e5c 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleServiceImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/user/TenantRoleServiceImpl.java
@@ -26,17 +26,19 @@ import 
org.apache.inlong.manager.dao.entity.InlongTenantEntity;
 import org.apache.inlong.manager.dao.entity.TenantUserRoleEntity;
 import org.apache.inlong.manager.dao.mapper.InlongTenantEntityMapper;
 import org.apache.inlong.manager.dao.mapper.TenantUserRoleEntityMapper;
+import org.apache.inlong.manager.pojo.common.PageResult;
 import org.apache.inlong.manager.pojo.user.TenantRoleInfo;
 import org.apache.inlong.manager.pojo.user.TenantRolePageRequest;
 import org.apache.inlong.manager.pojo.user.TenantRoleRequest;
 
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.TENANT_NOT_EXIST;
 
 /**
@@ -53,10 +55,13 @@ public class TenantRoleServiceImpl implements 
TenantRoleService {
     private InlongTenantEntityMapper tenantMapper;
 
     @Override
-    public PageInfo<TenantRoleInfo> listByCondition(TenantRolePageRequest 
request) {
+    public PageResult<TenantRoleInfo> listByCondition(TenantRolePageRequest 
request) {
         PageHelper.startPage(request.getPageNum(), request.getPageSize());
         Page<TenantUserRoleEntity> entityPage = 
tenantUserRoleEntityMapper.listByCondition(request);
-        return entityPage.toPageInfo(entity -> 
CommonBeanUtils.copyProperties(entity, TenantRoleInfo::new));
+        List<TenantRoleInfo> tenantRoleInfos = 
CommonBeanUtils.copyListProperties(entityPage, TenantRoleInfo::new);
+        return new PageResult<>(tenantRoleInfos,
+                entityPage.getTotal(),
+                entityPage.getPageNum(), entityPage.getPageSize());
     }
 
     @Override
diff --git 
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
 
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
index 2c6c25d995..bc13bd44ab 100644
--- 
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
+++ 
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
@@ -18,6 +18,7 @@
 package org.apache.inlong.manager.service.user;
 
 import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.pojo.common.PageResult;
 import org.apache.inlong.manager.pojo.user.LoginUserUtils;
 import org.apache.inlong.manager.pojo.user.TenantRoleInfo;
 import org.apache.inlong.manager.pojo.user.TenantRolePageRequest;
@@ -26,7 +27,6 @@ import org.apache.inlong.manager.pojo.user.UserInfo;
 import org.apache.inlong.manager.pojo.user.UserRoleCode;
 import org.apache.inlong.manager.service.ServiceBaseTest;
 
-import com.github.pagehelper.PageInfo;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Order;
@@ -106,8 +106,8 @@ public class TenantRoleServiceTest extends ServiceBaseTest {
         }
         TenantRolePageRequest pageRequest = new TenantRolePageRequest();
         pageRequest.setKeyword("pub");
-        PageInfo<TenantRoleInfo> infos = service.listByCondition(pageRequest);
-        Assertions.assertEquals(max, infos.getSize());
+        PageResult<TenantRoleInfo> infos = 
service.listByCondition(pageRequest);
+        Assertions.assertEquals(max, infos.getTotal());
     }
 
 }
\ No newline at end of file
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
index 020d8721e0..6806fd9e1e 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
@@ -18,6 +18,7 @@
 package org.apache.inlong.manager.web.controller;
 
 import org.apache.inlong.manager.common.enums.OperationType;
+import org.apache.inlong.manager.pojo.common.PageResult;
 import org.apache.inlong.manager.pojo.common.Response;
 import org.apache.inlong.manager.pojo.user.LoginUserUtils;
 import org.apache.inlong.manager.pojo.user.TenantRoleInfo;
@@ -27,7 +28,6 @@ import org.apache.inlong.manager.pojo.user.UserRoleCode;
 import org.apache.inlong.manager.service.operationlog.OperationLog;
 import org.apache.inlong.manager.service.user.TenantRoleService;
 
-import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
@@ -77,7 +77,7 @@ public class InlongTenantRoleController {
 
     @RequestMapping(value = "/role/tenant/list", method = RequestMethod.POST)
     @ApiOperation(value = "List tenant roles by paginating")
-    public Response<PageInfo<TenantRoleInfo>> listByCondition(@RequestBody 
TenantRolePageRequest request) {
+    public Response<PageResult<TenantRoleInfo>> listByCondition(@RequestBody 
TenantRolePageRequest request) {
         return Response.success(tenantRoleService.listByCondition(request));
     }
 

Reply via email to