1
0

feat(web): 增加数据资源更新接口

This commit is contained in:
2024-11-24 23:13:36 +08:00
parent d354cb9733
commit dd3ac59bee
3 changed files with 184 additions and 64 deletions

View File

@@ -21,6 +21,10 @@ function detailForm() {
left: 2, left: 2,
}, },
body: [ body: [
{
type: 'hidden',
name: 'id',
},
{ {
type: 'input-text', type: 'input-text',
name: 'name', name: 'name',
@@ -94,9 +98,14 @@ function detailForm() {
{ {
visibleOn: "${!static}", visibleOn: "${!static}",
type: 'input-file', type: 'input-file',
name: 'fileId', label: '数据文件',
description: '只适合小于1GB的资源文件使用大文件请使用其他资源类型', description: '只适合小于1GB的资源文件使用大文件请使用其他资源类型',
name: 'filename',
required: true,
...inputFileFormItemCommonOptions('.zip', size1GB), ...inputFileFormItemCommonOptions('.zip', size1GB),
autoFill: {
fileId: '${value|default:undefined}'
}
}, },
] ]
}, },
@@ -150,8 +159,12 @@ function detailForm() {
visibleOn: "${!static}", visibleOn: "${!static}",
type: 'input-file', type: 'input-file',
label: 'core-site.xml', label: 'core-site.xml',
name: 'coreSiteFileId', name: 'coreSiteFilename',
required: true,
...inputFileFormItemCommonOptions('.xml'), ...inputFileFormItemCommonOptions('.xml'),
autoFill: {
coreSiteFileId: '${value|default:undefined}'
}
}, },
{ {
visibleOn: "${static}", visibleOn: "${static}",
@@ -163,8 +176,12 @@ function detailForm() {
visibleOn: "${!static}", visibleOn: "${!static}",
type: 'input-file', type: 'input-file',
label: 'hdfs-site.xml', label: 'hdfs-site.xml',
name: 'hdfsSiteFileId', name: 'hdfsSiteFilename',
required: true,
...inputFileFormItemCommonOptions('.xml'), ...inputFileFormItemCommonOptions('.xml'),
autoFill: {
hdfsSiteFileId: '${value|default:undefined}'
}
}, },
] ]
}, },
@@ -229,7 +246,14 @@ function detailForm() {
] ]
}, },
{ {
visibleOn: "${formatType === 'JSON'}", visibleOn: "${formatType === 'JSON' && static}",
type: 'editor',
name: 'jsonSchemaText',
label: 'JSON格式',
language: 'json',
},
{
visibleOn: "${formatType === 'JSON' && !static}",
type: 'json-schema-editor', type: 'json-schema-editor',
name: 'jsonSchema', name: 'jsonSchema',
label: 'JSON格式', label: 'JSON格式',
@@ -239,7 +263,14 @@ function detailForm() {
mini: true, mini: true,
}, },
{ {
visibleOn: "${formatType === 'JSON_LINE'}", visibleOn: "${formatType === 'JSON_LINE' && static}",
type: 'editor',
name: 'jsonLineSchemaText',
label: 'JSON格式',
language: 'json',
},
{
visibleOn: "${formatType === 'JSON_LINE' && !static}",
type: 'json-schema-editor', type: 'json-schema-editor',
name: 'jsonLineSchema', name: 'jsonLineSchema',
label: 'JSON格式', label: 'JSON格式',
@@ -249,7 +280,14 @@ function detailForm() {
mini: true, mini: true,
}, },
{ {
visibleOn: "${formatType === 'CSV'}", visibleOn: "${formatType === 'CSV' && static}",
type: 'editor',
name: 'csvSchemaText',
label: 'JSON格式',
language: 'json',
},
{
visibleOn: "${formatType === 'CSV' && !static}",
type: 'json-schema-editor', type: 'json-schema-editor',
name: 'csvSchema', name: 'csvSchema',
label: 'CSV格式', label: 'CSV格式',
@@ -273,9 +311,12 @@ function detailForm() {
visibleOn: "${!static}", visibleOn: "${!static}",
type: 'input-file', type: 'input-file',
label: '资源示例', label: '资源示例',
name: 'exampleFilename',
description: '可以上传用于作为格式示范的样例数据', description: '可以上传用于作为格式示范的样例数据',
name: 'exampleFileId',
...inputFileFormItemCommonOptions(undefined, size500MB), ...inputFileFormItemCommonOptions(undefined, size500MB),
autoFill: {
exampleFileId: '${value|default:undefined}'
},
}, },
] ]
} }
@@ -326,4 +367,31 @@ export function resourceDetailDialog() {
}, },
} }
} }
}
export function resourceEditeDialog() {
return {
actionType: 'dialog',
dialog: {
title: '账号详情',
size: 'md',
actions: [
{
type: 'reset',
label: '重置',
},
{
type: 'submit',
label: '确定',
level: 'primary',
}
],
body: {
...detailForm(),
debug: true,
api: apiPost('${base}/data_resource/update'),
initApi: apiGet('${base}/data_resource/detail/${id}'),
},
}
}
} }

View File

@@ -1,5 +1,9 @@
import {resourceAddDialog, resourceDetailDialog} from "../../components/resource/dialog-resource.js"; import {
import {apiPost, copyField, crudCommonOptions} from "../../components/constants.js"; resourceAddDialog,
resourceDetailDialog,
resourceEditeDialog
} from "../../components/resource/dialog-resource.js";
import {apiPost, crudCommonOptions} from "../../components/constants.js";
export function tabData() { export function tabData() {
return { return {
@@ -26,12 +30,6 @@ export function tabData() {
label: '名称', label: '名称',
name: 'name', name: 'name',
width: 200, width: 200,
...copyField(
'name',
'查看详情',
undefined,
resourceDetailDialog(),
)
}, },
{ {
label: '描述', label: '描述',
@@ -50,7 +48,26 @@ export function tabData() {
type: 'operation', type: 'operation',
fixed: 'right', fixed: 'right',
className: 'nowrap', className: 'nowrap',
buttons: [] buttons: [
{
type: 'action',
label: '查看',
level: 'link',
...resourceDetailDialog(),
},
{
type: 'action',
label: '编辑',
level: 'link',
...resourceEditeDialog(),
},
{
type: 'action',
label: '删除',
level: 'link',
className: 'text-danger',
},
]
}, },
] ]
} }

View File

@@ -59,49 +59,8 @@ public class DataResourceController {
@PostMapping("/create") @PostMapping("/create")
public void create(@RequestBody CreateRequest request) throws JsonProcessingException { public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
log.info("Create request: {}", request); log.info("Create request: {}", request);
ResourceType type = null; ResourceType type = request.generateResourceType(dataFileService);
switch (request.resourceType) { ResourceFormat format = request.generateResourceFormat(mapper);
case API:
type = new ApiResourceType(request.apiUrl, request.apiUsername, request.apiPassword);
break;
case FILE:
DataFile dataFile = dataFileService.detail(request.fileId);
log.info("{}", dataFile);
type = new FileResourceType(dataFile);
break;
case DATABASE:
type = new DatabaseResourceType(
request.databaseJdbc,
request.databaseUsername,
request.databasePassword,
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, request.databaseType)
);
break;
case HDFS:
type = new HDFSResourceType(dataFileService.detail(request.coreSiteFileId), dataFileService.detail(request.hdfsSiteFileId));
break;
case FTP:
type = new FtpResourceType(request.ftpUrl, request.ftpUsername, request.ftpPassword, request.ftpPath, request.ftpRegexFilter);
break;
}
ResourceFormat format = null;
switch (request.formatType) {
case NONE:
format = new NoneResourceFormat();
break;
case LINE:
format = new LineResourceFormat();
break;
case JSON:
format = new JsonResourceFormat(mapper.writeValueAsString(request.jsonSchema));
break;
case JSON_LINE:
format = new JsonLineResourceFormat(mapper.writeValueAsString(request.jsonLineSchema));
break;
case CSV:
format = new CsvResourceFormat(mapper.writeValueAsString(request.csvSchema));
break;
}
dataResourceService.create(request.name, request.description, format, type, dataFileService.detail(request.exampleFileId)); dataResourceService.create(request.name, request.description, format, type, dataFileService.detail(request.exampleFileId));
} }
@@ -115,6 +74,11 @@ public class DataResourceController {
return AmisResponse.responseSuccess(new DataResourceDetail(mapper, dataResourceService.detail(id))); return AmisResponse.responseSuccess(new DataResourceDetail(mapper, dataResourceService.detail(id)));
} }
@PostMapping("/update/{id}")
public void update(@PathVariable Long id, @RequestBody UpdateRequest request) throws JsonProcessingException {
}
@Data @Data
public static class CreateRequest { public static class CreateRequest {
protected String name; protected String name;
@@ -137,9 +101,69 @@ public class DataResourceController {
protected String ftpRegexFilter; protected String ftpRegexFilter;
protected ResourceFormat.Type formatType; protected ResourceFormat.Type formatType;
protected Map<?, ?> jsonSchema; protected Map<?, ?> jsonSchema;
protected String jsonSchemaText;
protected Map<?, ?> jsonLineSchema; protected Map<?, ?> jsonLineSchema;
protected String jsonLineSchemaText;
protected Map<?, ?> csvSchema; protected Map<?, ?> csvSchema;
protected String csvSchemaText;
protected String exampleFileId; protected String exampleFileId;
public ResourceType generateResourceType(DataFileService dataFileService) {
ResourceType type = null;
switch (resourceType) {
case API:
type = new ApiResourceType(apiUrl, apiUsername, apiPassword);
break;
case FILE:
DataFile dataFile = dataFileService.detail(fileId);
log.info("{}", dataFile);
type = new FileResourceType(dataFile);
break;
case DATABASE:
type = new DatabaseResourceType(
databaseJdbc,
databaseUsername,
databasePassword,
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, databaseType)
);
break;
case HDFS:
type = new HDFSResourceType(dataFileService.detail(coreSiteFileId), dataFileService.detail(hdfsSiteFileId));
break;
case FTP:
type = new FtpResourceType(ftpUrl, ftpUsername, ftpPassword, ftpPath, ftpRegexFilter);
break;
}
return type;
}
public ResourceFormat generateResourceFormat(ObjectMapper mapper) throws JsonProcessingException {
ResourceFormat format = null;
switch (formatType) {
case NONE:
format = new NoneResourceFormat();
break;
case LINE:
format = new LineResourceFormat();
break;
case JSON:
format = new JsonResourceFormat(mapper.writeValueAsString(jsonSchema));
break;
case JSON_LINE:
format = new JsonLineResourceFormat(mapper.writeValueAsString(jsonLineSchema));
break;
case CSV:
format = new CsvResourceFormat(mapper.writeValueAsString(csvSchema));
break;
}
return format;
}
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class UpdateRequest extends CreateRequest {
private Long id;
} }
@Data @Data
@@ -167,6 +191,10 @@ public class DataResourceController {
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@NoArgsConstructor @NoArgsConstructor
public static final class DataResourceDetail extends CreateRequest { public static final class DataResourceDetail extends CreateRequest {
private String filename;
private String coreSiteFilename;
private String hdfsSiteFilename;
private String exampleFilename;
private LocalDateTime createdTime; private LocalDateTime createdTime;
private String createdUsername; private String createdUsername;
private LocalDateTime modifiedTime; private LocalDateTime modifiedTime;
@@ -186,7 +214,8 @@ public class DataResourceController {
break; break;
case FILE: case FILE:
FileResourceType fileType = (FileResourceType) dataResource.getType(); FileResourceType fileType = (FileResourceType) dataResource.getType();
this.fileId = fileType.getFile().getFilename(); this.fileId = fileType.getFile().getId().toString();
this.filename = fileType.getFile().getFilename();
break; break;
case DATABASE: case DATABASE:
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType(); DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
@@ -197,8 +226,10 @@ public class DataResourceController {
break; break;
case HDFS: case HDFS:
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType(); HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
this.coreSiteFileId = hdfsType.getCoreSite().getFilename(); this.coreSiteFileId = hdfsType.getCoreSite().getId().toString();
this.hdfsSiteFileId = hdfsType.getHdfsSite().getFilename(); this.coreSiteFilename = hdfsType.getCoreSite().getFilename();
this.hdfsSiteFileId = hdfsType.getHdfsSite().getId().toString();
this.hdfsSiteFilename = hdfsType.getHdfsSite().getFilename();
break; break;
case FTP: case FTP:
FtpResourceType ftpType = (FtpResourceType) dataResource.getType(); FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
@@ -216,19 +247,23 @@ public class DataResourceController {
break; break;
case JSON: case JSON:
JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat(); JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat();
this.jsonSchemaText = jsonFormat.getSchema();
this.jsonSchema = mapper.readValue(jsonFormat.getSchema(), Map.class); this.jsonSchema = mapper.readValue(jsonFormat.getSchema(), Map.class);
break; break;
case JSON_LINE: case JSON_LINE:
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat(); JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
this.jsonLineSchemaText = jsonLineFormat.getSchema();
this.jsonLineSchema = mapper.readValue(jsonLineFormat.getSchema(), Map.class); this.jsonLineSchema = mapper.readValue(jsonLineFormat.getSchema(), Map.class);
break; break;
case CSV: case CSV:
CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat(); CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat();
this.jsonLineSchema = mapper.readValue(csvFormat.getSchema(), Map.class); this.csvSchemaText = csvFormat.getSchema();
this.csvSchema = mapper.readValue(csvFormat.getSchema(), Map.class);
break; break;
} }
if (ObjectUtil.isNotNull(dataResource.getExample())) { if (ObjectUtil.isNotNull(dataResource.getExample())) {
this.exampleFileId = dataResource.getExample().getFilename(); this.exampleFileId = dataResource.getExample().getId().toString();
this.exampleFilename = dataResource.getExample().getFilename();
} }
this.createdUsername = dataResource.getCreatedUser().getUsername(); this.createdUsername = dataResource.getCreatedUser().getUsername();