vernedeng commented on code in PR #8097:
URL: https://github.com/apache/inlong/pull/8097#discussion_r1206156863


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/tenant/InlongTenantServiceImpl.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.service.tenant;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.inlong.manager.common.consts.InlongConstants;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.InlongTenantEntity;
+import org.apache.inlong.manager.dao.mapper.InlongTenantEntityMapper;
+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 org.apache.inlong.manager.service.user.LoginUserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+public class InlongTenantServiceImpl implements InlongTenantService {
+
+    @Autowired
+    private InlongTenantEntityMapper inlongTenantEntityMapper;
+
+    @Override
+    public InlongTenantInfo get(String name) {
+        InlongTenantEntity entity = 
inlongTenantEntityMapper.selectByName(name);
+        return CommonBeanUtils.copyProperties(entity, InlongTenantInfo::new);
+    }
+
+    @Override
+    public Integer save(InlongTenantRequest request) {
+        String name = request.getName();
+        InlongTenantEntity existEntity = 
inlongTenantEntityMapper.selectByName(name);
+        if (existEntity != null) {
+            String errMsg = String.format("tenant already exist for name=%s)", 
name);
+            log.error(errMsg);
+            throw new BusinessException(errMsg);
+        }
+        InlongTenantEntity entity = CommonBeanUtils.copyProperties(request, 
InlongTenantEntity::new);
+        String operator = LoginUserUtils.getLoginUser().getName();
+        entity.setCreator(operator);
+        entity.setModifier(operator);
+        inlongTenantEntityMapper.insert(entity);
+        return entity.getId();
+    }
+
+    @Override
+    public PageInfo<InlongTenantInfo> listByCondition(InlongTenantPageRequest 
request) {
+        PageHelper.startPage(request.getPageNum(), request.getPageSize());
+        Page<InlongTenantEntity> entityPage = 
inlongTenantEntityMapper.selectByCondition(request);
+        return entityPage
+                .toPageInfo(entity -> CommonBeanUtils.copyProperties(entity, 
InlongTenantInfo::new));
+    }
+
+    @Override
+    public Boolean update(InlongTenantRequest request) {
+        InlongTenantEntity exist = 
inlongTenantEntityMapper.selectByName(request.getName());

Review Comment:
   If somebody changes the tenant name, all the related resources need to be 
changed also. Hence I don't think it's a good idea to allow tenant owner to 
change tenant name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to