|
27 | 27 | import com.flow.platform.api.security.WebSecurity; |
28 | 28 | import com.flow.platform.api.service.GitService; |
29 | 29 | import com.flow.platform.api.service.node.YmlService; |
| 30 | +import com.flow.platform.api.util.CommonUtil; |
30 | 31 | import com.flow.platform.core.exception.IllegalParameterException; |
31 | 32 | import com.flow.platform.util.StringUtil; |
32 | 33 | import com.google.common.base.Strings; |
| 34 | +import java.io.IOException; |
33 | 35 | import java.util.List; |
34 | 36 | import java.util.Map; |
35 | 37 | import java.util.Set; |
| 38 | +import javax.servlet.http.HttpServletResponse; |
36 | 39 | import org.springframework.beans.factory.annotation.Autowired; |
| 40 | +import org.springframework.core.io.Resource; |
37 | 41 | import org.springframework.web.bind.annotation.DeleteMapping; |
38 | 42 | import org.springframework.web.bind.annotation.GetMapping; |
39 | 43 | import org.springframework.web.bind.annotation.PostMapping; |
40 | 44 | import org.springframework.web.bind.annotation.RequestBody; |
41 | 45 | import org.springframework.web.bind.annotation.RequestMapping; |
42 | 46 | import org.springframework.web.bind.annotation.RequestParam; |
| 47 | +import org.springframework.web.bind.annotation.RequestPart; |
43 | 48 | import org.springframework.web.bind.annotation.RestController; |
| 49 | +import org.springframework.web.multipart.MultipartFile; |
44 | 50 |
|
45 | 51 | /** |
46 | 52 | * @author yh@firim |
@@ -416,6 +422,53 @@ public String createFromYml(@RequestBody(required = false) String yml) { |
416 | 422 | return yml; |
417 | 423 | } |
418 | 424 |
|
| 425 | + /** |
| 426 | + * @api {post} /flows/:root/yml/upload upload yml |
| 427 | + * @apiParam {String} root flow node name to set yml content |
| 428 | + * @apiParam file |
| 429 | + * @apiGroup Flow Yml |
| 430 | + * @apiDescription Create yml for flow, |
| 431 | + * the flow name must be matched with flow name defined in yml |
| 432 | + * |
| 433 | + * @apiSuccessExample {json} Success-Response |
| 434 | + * |
| 435 | + * yml body |
| 436 | + */ |
| 437 | + @PostMapping("/{root}/yml/upload") |
| 438 | + @WebSecurity(action = Actions.FLOW_CREATE) |
| 439 | + public String createFromUploadYml(@RequestPart MultipartFile file) throws IOException { |
| 440 | + String yml = CommonUtil.commonsMultipartFileToString(file); |
| 441 | + if (Strings.isNullOrEmpty(yml)) { |
| 442 | + throw new IllegalParameterException("file is not available"); |
| 443 | + } |
| 444 | + |
| 445 | + nodeService.createOrUpdateYml(currentNodePath.get(), yml); |
| 446 | + return yml; |
| 447 | + } |
| 448 | + |
| 449 | + |
| 450 | + /** |
| 451 | + * @api {post} /flows/:root/yml/download download yml |
| 452 | + * @apiParam {String} root flow node name to set yml content |
| 453 | + * @apiGroup Flow Yml |
| 454 | + * @apiDescription download yml for flow, |
| 455 | + * the flow name must be matched with flow name defined in yml |
| 456 | + * |
| 457 | + * @apiSuccessExample {json} Success-Response |
| 458 | + * |
| 459 | + * yml file |
| 460 | + */ |
| 461 | + @GetMapping("/{root}/yml/download") |
| 462 | + @WebSecurity(action = Actions.FLOW_CREATE) |
| 463 | + public Resource downloadFlowYml(HttpServletResponse httpResponse) { |
| 464 | + String path = currentNodePath.get(); |
| 465 | + Node root = nodeService.find(path).root(); |
| 466 | + httpResponse.setHeader( |
| 467 | + "Content-Disposition", |
| 468 | + String.format("attachment; filename=%s", ".flow.yml")); |
| 469 | + return ymlService.getResource(root); |
| 470 | + } |
| 471 | + |
419 | 472 | /** |
420 | 473 | * @api {post} /flows/:root/users/auth |
421 | 474 | * @apiParam {String} root flow node name |
@@ -481,7 +534,7 @@ public List<User> flowAuthUsers(@RequestBody ListParam<String> listParam) { |
481 | 534 | * } |
482 | 535 | */ |
483 | 536 | @PostMapping("/{root}/trigger") |
484 | | - public Node trigger(@RequestBody TriggerParam triggerParam){ |
| 537 | + public Node trigger(@RequestBody TriggerParam triggerParam) { |
485 | 538 | String path = currentNodePath.get(); |
486 | 539 | Node flow = nodeService.find(path).root(); |
487 | 540 | envService.save(flow, triggerParam.toEnv(), true); |
|
0 commit comments