feat(web): 增加数据资源更新接口
This commit is contained in:
@@ -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