|
|
|
|
package kr.re.etri.autoflow.controllers;
|
|
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Content;
|
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import kr.re.etri.autoflow.entity.StorageAttachmentEntity;
|
|
|
|
|
import kr.re.etri.autoflow.service.DatasetService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Tag(name = "Dataset API", description = "외부 데이터셋 목록 조회 API (Python requests 코드 기반)")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/datasets")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class ExternalDataSetController {
|
|
|
|
|
|
|
|
|
|
private final DatasetService datasetService;
|
|
|
|
|
private final kr.re.etri.autoflow.service.StorageAttachmentService storageAttachmentService;
|
|
|
|
|
|
|
|
|
|
@Operation(
|
|
|
|
|
summary = "데이터셋 목록 조회",
|
|
|
|
|
description = "외부 API(/export/dataset_list)를 호출하여 데이터셋 목록을 조회합니다."
|
|
|
|
|
)
|
|
|
|
|
@ApiResponses({
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "성공적으로 데이터셋을 조회했습니다."),
|
|
|
|
|
@ApiResponse(responseCode = "400", description = "잘못된 요청입니다.", content = @Content),
|
|
|
|
|
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content)
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
public ResponseEntity<?> getDatasetList(
|
|
|
|
|
@Parameter(description = "프로젝트 인덱스", example = "10")
|
|
|
|
|
@RequestParam(required = false) Integer ds_prj_idx,
|
|
|
|
|
@Parameter(description = "검색 키워드", example = "")
|
|
|
|
|
@RequestParam(required = false) String search_keyword,
|
|
|
|
|
@Parameter(description = "그룹 이름", example = "")
|
|
|
|
|
@RequestParam(required = false) String grp_name
|
|
|
|
|
) {
|
|
|
|
|
Map<String, Object> result = datasetService.getDatasetList(ds_prj_idx, search_keyword, grp_name);
|
|
|
|
|
return ResponseEntity.ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "외부 데이터셋 다운로드 후 S3 저장", description = "Kubeflow 등 외부 API로부터 데이터셋을 다운로드하고 MinIO에 업로드합니다.")
|
|
|
|
|
@PostMapping("/dataset/save")
|
|
|
|
|
public ResponseEntity<Map<String, Object>> saveDatasetToS3(
|
|
|
|
|
@RequestParam String datasetName,
|
|
|
|
|
@RequestParam(required = false) String path,
|
|
|
|
|
@RequestParam(required = true) Long refId,
|
|
|
|
|
@RequestParam(defaultValue = "DATASET") String refType,
|
|
|
|
|
@RequestParam(required = false) String title,
|
|
|
|
|
@RequestParam(required = false) String description,
|
|
|
|
|
@RequestParam(defaultValue = "1") Integer version,
|
|
|
|
|
@RequestParam String regUserId,
|
|
|
|
|
@RequestParam Long projectId
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
StorageAttachmentEntity saved = datasetService.downloadDataset(
|
|
|
|
|
datasetName, path, refId, refType, title, description, version, regUserId, projectId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
|
response.put("attachment", saved);
|
|
|
|
|
response.put("minioUrl", storageAttachmentService.getFileUrl(saved.getStoragePath()));
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok(response);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("데이터셋 저장 실패", e);
|
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
|
.body(Map.of("error", e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|