You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/08/09 03:00:40 UTC

[GitHub] [inlong] fuweng11 commented on a diff in pull request #5381: [INLONG-5380][Manager] Modify the saving function of datanode

fuweng11 commented on code in PR #5381:
URL: https://github.com/apache/inlong/pull/5381#discussion_r940844901


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/DataNodeServiceImpl.java:
##########
@@ -65,34 +70,39 @@ public Integer save(DataNodeRequest request, String operator) {
             LOGGER.error(errMsg);
             throw new BusinessException(errMsg);
         }
-        DataNodeEntity entity = CommonBeanUtils.copyProperties(request, DataNodeEntity::new);
-        entity.setCreator(operator);
-        entity.setModifier(operator);
-        dataNodeMapper.insert(entity);
-
+        // According to the data type, save sink information
+        DataNodeOperator operation = operatorFactory.getInstance(request.getType());
+        int id = operation.saveOpt(request, operator);
         LOGGER.debug("success to save data node={}", request);
-        return entity.getId();
+        return id;
     }
 
     @Override
-    public DataNodeResponse get(Integer id) {
+    public DataNodeInfo get(Integer id) {
         DataNodeEntity entity = dataNodeMapper.selectById(id);
         if (entity == null) {
             LOGGER.error("data node not found by id={}", id);
             throw new BusinessException("data node not found");
         }
-        DataNodeResponse response = CommonBeanUtils.copyProperties(entity, DataNodeResponse::new);
+        String dataNodeType = entity.getType();
+        DataNodeOperator operation = operatorFactory.getInstance(dataNodeType);
+        DataNodeInfo dataNodeInfo = operation.getFromEntity(entity);
+
         LOGGER.debug("success to get data node info by id={}", id);
-        return response;
+        return dataNodeInfo;
     }
 
     @Override
-    public PageInfo<DataNodeResponse> list(DataNodePageRequest request) {
+    public PageInfo<DataNodeInfo> list(DataNodePageRequest request) {
         PageHelper.startPage(request.getPageNum(), request.getPageSize());
         Page<DataNodeEntity> entityPage = (Page<DataNodeEntity>) dataNodeMapper.selectByCondition(request);
-        List<DataNodeResponse> responseList = CommonBeanUtils.copyListProperties(entityPage, DataNodeResponse::new);
-        PageInfo<DataNodeResponse> page = new PageInfo<>(responseList);
-        page.setTotal(entityPage.getTotal());
+        List<DataNodeInfo> list = entityPage.stream()
+                .map(entity -> {
+                    DataNodeOperator instance = operatorFactory.getInstance(entity.getType());
+                    return instance.getFromEntity(entity);
+                }).collect(Collectors.toList());
+        PageInfo<DataNodeInfo> page = new PageInfo<>(list);
+        page.setTotal(list.size());

Review Comment:
   The size of the` list` is equal to the size of the `entitypage`. The `list` is converted from the `entitypage`.



-- 
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-unsubscribe@inlong.apache.org

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