You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "healchow (via GitHub)" <gi...@apache.org> on 2023/04/07 09:30:38 UTC

[GitHub] [inlong] healchow commented on a diff in pull request #7793: [INLONG-7792][Manager] Support export Excel template file of StreamSource

healchow commented on code in PR #7793:
URL: https://github.com/apache/inlong/pull/7793#discussion_r1160579045


##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongStreamController.java:
##########
@@ -183,4 +191,22 @@ public Response<List<StreamField>> parseFields(@RequestBody ParseFieldRequest pa
         return Response.success(streamService.parseFields(parseFieldRequest));
     }
 
+    @RequestMapping(value = "/stream/fieldsImportTemplate", method = RequestMethod.GET)
+    @ApiOperation(value = "Download fields import template")
+    public void downloadFieldsImportTemplate(HttpServletResponse response) {

Review Comment:
   Suggest return true of false for the API method, you can wrap it with `Response`.



##########
inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongStreamController.java:
##########
@@ -183,4 +191,22 @@ public Response<List<StreamField>> parseFields(@RequestBody ParseFieldRequest pa
         return Response.success(streamService.parseFields(parseFieldRequest));
     }
 
+    @RequestMapping(value = "/stream/fieldsImportTemplate", method = RequestMethod.GET)
+    @ApiOperation(value = "Download fields import template")
+    public void downloadFieldsImportTemplate(HttpServletResponse response) {
+        String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss"));
+        String fileName = String.format("InLong-stream-fields-template-%s.xlsx", date);
+        response.setHeader("Content-Disposition",
+                "attachment;filename=" + fileName);
+        response.setContentType("multipart/form-data");
+
+        try {
+            ServletOutputStream outputStream = response.getOutputStream();
+            ExcelTool.write(StreamField.class, outputStream);
+
+        } catch (IOException e) {
+            log.error("Can not properly download Excel file", e);

Review Comment:
   If error, please throw an `BusinessException`.



-- 
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