feat(web): 增加数据资源更新接口
This commit is contained in:
@@ -21,6 +21,10 @@ function detailForm() {
|
||||
left: 2,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'hidden',
|
||||
name: 'id',
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
@@ -94,9 +98,14 @@ function detailForm() {
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
name: 'fileId',
|
||||
label: '数据文件',
|
||||
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
||||
name: 'filename',
|
||||
required: true,
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||
autoFill: {
|
||||
fileId: '${value|default:undefined}'
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -150,8 +159,12 @@ function detailForm() {
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
label: 'core-site.xml',
|
||||
name: 'coreSiteFileId',
|
||||
name: 'coreSiteFilename',
|
||||
required: true,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
autoFill: {
|
||||
coreSiteFileId: '${value|default:undefined}'
|
||||
}
|
||||
},
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
@@ -163,8 +176,12 @@ function detailForm() {
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
label: 'hdfs-site.xml',
|
||||
name: 'hdfsSiteFileId',
|
||||
name: 'hdfsSiteFilename',
|
||||
required: true,
|
||||
...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',
|
||||
name: 'jsonSchema',
|
||||
label: 'JSON格式',
|
||||
@@ -239,7 +263,14 @@ function detailForm() {
|
||||
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',
|
||||
name: 'jsonLineSchema',
|
||||
label: 'JSON格式',
|
||||
@@ -249,7 +280,14 @@ function detailForm() {
|
||||
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',
|
||||
name: 'csvSchema',
|
||||
label: 'CSV格式',
|
||||
@@ -273,9 +311,12 @@ function detailForm() {
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
label: '资源示例',
|
||||
name: 'exampleFilename',
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
name: 'exampleFileId',
|
||||
...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}'),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
import {resourceAddDialog, resourceDetailDialog} from "../../components/resource/dialog-resource.js";
|
||||
import {apiPost, copyField, crudCommonOptions} from "../../components/constants.js";
|
||||
import {
|
||||
resourceAddDialog,
|
||||
resourceDetailDialog,
|
||||
resourceEditeDialog
|
||||
} from "../../components/resource/dialog-resource.js";
|
||||
import {apiPost, crudCommonOptions} from "../../components/constants.js";
|
||||
|
||||
export function tabData() {
|
||||
return {
|
||||
@@ -26,12 +30,6 @@ export function tabData() {
|
||||
label: '名称',
|
||||
name: 'name',
|
||||
width: 200,
|
||||
...copyField(
|
||||
'name',
|
||||
'查看详情',
|
||||
undefined,
|
||||
resourceDetailDialog(),
|
||||
)
|
||||
},
|
||||
{
|
||||
label: '描述',
|
||||
@@ -50,7 +48,26 @@ export function tabData() {
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: []
|
||||
buttons: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...resourceDetailDialog(),
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '编辑',
|
||||
level: 'link',
|
||||
...resourceEditeDialog(),
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '删除',
|
||||
level: 'link',
|
||||
className: 'text-danger',
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -59,49 +59,8 @@ public class DataResourceController {
|
||||
@PostMapping("/create")
|
||||
public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
|
||||
log.info("Create request: {}", request);
|
||||
ResourceType type = null;
|
||||
switch (request.resourceType) {
|
||||
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;
|
||||
}
|
||||
ResourceType type = request.generateResourceType(dataFileService);
|
||||
ResourceFormat format = request.generateResourceFormat(mapper);
|
||||
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)));
|
||||
}
|
||||
|
||||
@PostMapping("/update/{id}")
|
||||
public void update(@PathVariable Long id, @RequestBody UpdateRequest request) throws JsonProcessingException {
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CreateRequest {
|
||||
protected String name;
|
||||
@@ -137,9 +101,69 @@ public class DataResourceController {
|
||||
protected String ftpRegexFilter;
|
||||
protected ResourceFormat.Type formatType;
|
||||
protected Map<?, ?> jsonSchema;
|
||||
protected String jsonSchemaText;
|
||||
protected Map<?, ?> jsonLineSchema;
|
||||
protected String jsonLineSchemaText;
|
||||
protected Map<?, ?> csvSchema;
|
||||
protected String csvSchemaText;
|
||||
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
|
||||
@@ -167,6 +191,10 @@ public class DataResourceController {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
public static final class DataResourceDetail extends CreateRequest {
|
||||
private String filename;
|
||||
private String coreSiteFilename;
|
||||
private String hdfsSiteFilename;
|
||||
private String exampleFilename;
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
@@ -186,7 +214,8 @@ public class DataResourceController {
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||
this.fileId = fileType.getFile().getFilename();
|
||||
this.fileId = fileType.getFile().getId().toString();
|
||||
this.filename = fileType.getFile().getFilename();
|
||||
break;
|
||||
case DATABASE:
|
||||
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
||||
@@ -197,8 +226,10 @@ public class DataResourceController {
|
||||
break;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||
this.coreSiteFileId = hdfsType.getCoreSite().getFilename();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getFilename();
|
||||
this.coreSiteFileId = hdfsType.getCoreSite().getId().toString();
|
||||
this.coreSiteFilename = hdfsType.getCoreSite().getFilename();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getId().toString();
|
||||
this.hdfsSiteFilename = hdfsType.getHdfsSite().getFilename();
|
||||
break;
|
||||
case FTP:
|
||||
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
||||
@@ -216,19 +247,23 @@ public class DataResourceController {
|
||||
break;
|
||||
case JSON:
|
||||
JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat();
|
||||
this.jsonSchemaText = jsonFormat.getSchema();
|
||||
this.jsonSchema = mapper.readValue(jsonFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
|
||||
this.jsonLineSchemaText = jsonLineFormat.getSchema();
|
||||
this.jsonLineSchema = mapper.readValue(jsonLineFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case CSV:
|
||||
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;
|
||||
}
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user