Skip to content

Commit

Permalink
[Feature-3034][admin] Support task export (DataLinkDC#3808)
Browse files Browse the repository at this point in the history
Co-authored-by: suxinshuo <[email protected]>
Co-authored-by: suxinshuo <[email protected]>
  • Loading branch information
3 people authored Sep 18, 2024
1 parent 19ffae8 commit 43b6486
Show file tree
Hide file tree
Showing 24 changed files with 1,046 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@
import org.dinky.data.constant.DirConstant;
import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.dto.CatalogueTreeQueryDTO;
import org.dinky.data.dto.ImportCatalogueDTO;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.Catalogue;
import org.dinky.data.result.Result;
import org.dinky.data.vo.ExportCatalogueVO;
import org.dinky.data.vo.TreeVo;
import org.dinky.service.TaskService;
import org.dinky.service.catalogue.CatalogueService;

import java.io.File;
import java.util.List;

import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand All @@ -46,6 +51,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.io.FileUtil;
Expand Down Expand Up @@ -250,4 +256,38 @@ public Result<Void> copyTask(@RequestBody Catalogue catalogue) {
public Result<Void> deleteCatalogueById(@CatalogueId @RequestParam Integer id) {
return catalogueService.deleteCatalogueById(id);
}

/**
* export catalogue by id
*
* @param id catalogue id
* @return {@link ResponseEntity}
*/
@GetMapping("/export")
@Log(title = "Export Catalogue", businessType = BusinessType.EXPORT)
@ApiOperation("Export Catalogue")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer", dataTypeClass = Integer.class)
public ResponseEntity<?> exportCatalogue(@RequestParam Integer id) {
ExportCatalogueVO exportCatalogueVo = catalogueService.exportCatalogue(id);
// convert the return value to file at the interface level
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + exportCatalogueVo.getFileName());
headers.add(HttpHeaders.CONTENT_TYPE, "application/json");
return ResponseEntity.ok().headers(headers).body(exportCatalogueVo.getDataJson());
}

/**
* import catalogue by parent id
*
* @return {@link Result}< {@link Void}>}
*/
@PostMapping("/import")
@Log(title = "Import Catalogue", businessType = BusinessType.IMPORT)
@ApiOperation("Import Catalogue")
public Result<Void> importCatalogue(MultipartHttpServletRequest request) {
// assemble dto objects and shield service requests
ImportCatalogueDTO importCatalogueDto = ImportCatalogueDTO.build(request);
catalogueService.importCatalogue(importCatalogueDto);
return Result.succeed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* 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.dinky.data.bo.catalogue.export;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExportCatalogueBO {

private String name;

private Boolean enabled;

private Boolean isLeaf;

private ExportTaskBO task;

private String type;

private List<ExportCatalogueBO> children;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
*
* 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.dinky.data.bo.catalogue.export;

import org.dinky.data.model.ext.TaskExtConfig;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExportTaskBO {

private String name;

private String dialect;

private String type;

private Integer checkPoint;

private Integer savePointStrategy;

private Integer parallelism;

private Boolean fragment;

private Boolean statementSet;

private Boolean batchModel;

private Integer envId;

private Integer alertGroupId;

private TaskExtConfig configJson;

private String note;

private Integer step;

private Boolean enabled;

private String statement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
*
* 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.dinky.data.dto;

import org.dinky.data.bo.catalogue.export.ExportCatalogueBO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import cn.hutool.json.JSONUtil;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Getter
@Builder
public class ImportCatalogueDTO {

private Integer parentCatalogueId;

private ExportCatalogueBO exportCatalogue;

public static ImportCatalogueDTO build(MultipartHttpServletRequest request) {
int parentCatalogueId = Integer.parseInt(request.getParameter("pid"));
ExportCatalogueBO exportCatalogue = null;
MultipartFile file = request.getFile("file");
if (Objects.isNull(file)) {
return null;
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
content.append(line);
}
exportCatalogue = JSONUtil.toBean(content.toString(), ExportCatalogueBO.class);
} catch (IOException e) {
log.error("Convert MultipartHttpServletRequest to ExportCatalogueBO failed", e);
}
return ImportCatalogueDTO.builder()
.parentCatalogueId(parentCatalogueId)
.exportCatalogue(exportCatalogue)
.build();
}
}
41 changes: 41 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/vo/ExportCatalogueVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* 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.dinky.data.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "ExportCatalogueVO", description = "The return value of export catalogue")
public class ExportCatalogueVO {

@ApiModelProperty(value = "FileName", dataType = "String", example = "data.json")
private String fileName;

@ApiModelProperty(value = "DataJson", dataType = "String")
private String dataJson;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import org.dinky.data.dto.CatalogueTaskDTO;
import org.dinky.data.dto.CatalogueTreeQueryDTO;
import org.dinky.data.dto.ImportCatalogueDTO;
import org.dinky.data.model.Catalogue;
import org.dinky.data.result.Result;
import org.dinky.data.vo.ExportCatalogueVO;
import org.dinky.data.vo.TreeVo;
import org.dinky.mybatis.service.ISuperService;

Expand Down Expand Up @@ -157,4 +159,19 @@ public interface CatalogueService extends ISuperService<Catalogue> {
* @return
*/
Boolean checkTaskOperatePermission(Integer catalogueId);

/**
* Export catalogue by id
*
* @param catalogueId catalogue id
* @return export catalogue vo
*/
ExportCatalogueVO exportCatalogue(Integer catalogueId);

/**
* Import catalogue
*
* @param importCatalogueDto ImportCatalogueDTO
*/
void importCatalogue(ImportCatalogueDTO importCatalogueDto);
}
Loading

0 comments on commit 43b6486

Please sign in to comment.