组件代码学生端动态展示、超管端支持更新修改(jupyter)

master
@t2652009480 8 months ago
parent 634c1da3af
commit b7618df905

@ -20,6 +20,7 @@ import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
@ -33,6 +34,8 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -127,11 +130,11 @@ public class AdminComponentCodeController {
@ApiOperation("编辑")
@AnonymousAccess
@Transactional
public ResultEntity<String> updateAdminData(@ApiParam("案例ID") @RequestParam Integer id,
@ApiParam("代码内容")@RequestParam(required = false) String codeContent,
@ApiParam("参数释义")@RequestParam(required = false) String parameterContent,
@ApiParam("步骤名称(一级标签)")@RequestParam(required = false) String stepName,
@ApiParam("案例名称(二级标签)")@RequestParam(required = false) String caseName) {
public ResultEntity<String> updateAdminData(@ApiParam("案例ID") @RequestBody Integer id,
@ApiParam("代码内容")@RequestBody(required = false) String codeContent,
@ApiParam("参数释义")@RequestBody(required = false) String parameterContent,
@ApiParam("步骤名称(一级标签)")@RequestBody(required = false) String stepName,
@ApiParam("案例名称(二级标签)")@RequestBody(required = false) String caseName) {
//编辑
try {
AdminComponentCodeWithBLOBs adminComponentCode = new AdminComponentCodeWithBLOBs();
@ -241,7 +244,7 @@ public class AdminComponentCodeController {
@GetMapping("/createNoteBook")
@AnonymousAccess
public ResultEntity createNoteBook(@ApiParam("参数为:案例名") String name,
@ApiParam("代码内容") String codeContent) {
@ApiParam("代码内容") String codeContent){
//判断有无这个案例
//
@ -277,10 +280,28 @@ public class AdminComponentCodeController {
return new ResultEntity<>(HttpStatus.BAD_REQUEST,"Token不存在");
}
try (CloseableHttpClient client = HttpClients.createDefault()) {
// String notebookContent = "{"
// + "\"cells\": ["
// + "{"
// + "\"cell_type\": \"code\","
// + "\"execution_count\": null,"
// + "\"metadata\": {},"
// + "\"outputs\": [],"
// + "\"source\": [" + codeContent + "]"
// + "}"
// + "],"
// + "\"metadata\": {"
// + " \"kernelspec\": {"
// + " \"display_name\": \"Python 3\","
// + " \"language\": \"python\","
// + " \"name\": \"python3\""
// + " }"
// + "},"
// + "\"nbformat\": 4,"
// + "\"nbformat_minor\": 2"
// + "}";
String notebookContent = "{"
+ "\"cells\": ["
+ "{"
@ -288,8 +309,8 @@ public class AdminComponentCodeController {
+ "\"execution_count\": null,"
+ "\"metadata\": {},"
+ "\"outputs\": [],"
+ "\"source\": ["+codeContent+"]"
+ "},"
+ "\"source\": [\"" + codeContent.replace("\n", "\\n").replace("\"", "\\\"") + "\"]"
+ "}"
// + "{"
// + "\"cell_type\": \"raw\","
// + "\"execution_count\": null,"
@ -297,11 +318,11 @@ public class AdminComponentCodeController {
// + "\"outputs\": [],"
// + "\"source\": [\"print('This is text!')\"]"
// + "},"
+ "{"
+ "\"cell_type\": \"markdown\","
+ "\"metadata\": {},"
+ "\"source\": [\"# Markdown Cell\\n\", \"This is a markdown cell.\"]"
+ "}"
// + "{"
// + "\"cell_type\": \"markdown\","
// + "\"metadata\": {},"
// + "\"source\": [\"# Markdown Cell\\n\", \"This is a markdown cell.\"]"
// + "}"
+ "],"
+ "\"metadata\": {"
+ " \"kernelspec\": {"
@ -325,8 +346,9 @@ public class AdminComponentCodeController {
createNotebookRequest.addHeader("Authorization", "token " + adminJupyterTokenList.get(0).getToken());
createNotebookRequest.addHeader("Content-Type", "application/json");
createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}"));
createNotebookRequest.addHeader("Content-Type", "application/json charset=UTF-8");
//createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}"));
createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}", ContentType.APPLICATION_JSON.withCharset("UTF-8")));
try (CloseableHttpResponse createNotebookResponse = client.execute(createNotebookRequest)) {
int statusCode = createNotebookResponse.getStatusLine().getStatusCode();

Loading…
Cancel
Save