shp 파일 geosjon 등록추가, 파일다운로드 파일명 오류 수정
This commit is contained in:
@@ -6,17 +6,50 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Log4j2
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ExternalJarRunner {
|
||||
|
||||
public void run(String jarPath, String batchIds, String inferenceId, String mapIds) {
|
||||
private static final long TIMEOUT_MINUTES = 30;
|
||||
|
||||
/**
|
||||
* shp 파일 생성
|
||||
*
|
||||
* @param jarPath jar 경로
|
||||
* @param batchIds 배치 아이디
|
||||
* @param inferenceId uid
|
||||
* @param mapIds 도엽 Id
|
||||
*/
|
||||
public void run(String jarPath, String batchIds, String inferenceId, String mapIds) {
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
addArg(args, "converter.inference-id", inferenceId);
|
||||
addArg(args, "converter.map-ids", mapIds);
|
||||
addArg(args, "converter.batch-ids", batchIds);
|
||||
|
||||
execJar(jarPath, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* geoserver 등록
|
||||
*
|
||||
* @param jarPath jar 파일경로
|
||||
* @param register shp 경로
|
||||
* @param layer geoserver에 등록될 레이어 이름
|
||||
*/
|
||||
public void run(String jarPath, String register, String layer) {
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
addArg(args, "register", register);
|
||||
addArg(args, "layer", layer);
|
||||
|
||||
execJar(jarPath, args);
|
||||
}
|
||||
|
||||
private void execJar(String jarPath, List<String> args) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
try {
|
||||
@@ -24,16 +57,7 @@ public class ExternalJarRunner {
|
||||
cmd.add("java");
|
||||
cmd.add("-jar");
|
||||
cmd.add(jarPath);
|
||||
|
||||
if (inferenceId != null && !inferenceId.isBlank()) {
|
||||
cmd.add("--converter.inference-id=" + inferenceId);
|
||||
}
|
||||
if (mapIds != null && !mapIds.isBlank()) {
|
||||
cmd.add("--converter.map-ids=" + mapIds);
|
||||
}
|
||||
if (batchIds != null && !batchIds.isBlank()) {
|
||||
cmd.add("--converter.batch-ids=" + batchIds);
|
||||
}
|
||||
cmd.addAll(args);
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd);
|
||||
pb.redirectErrorStream(true);
|
||||
@@ -49,7 +73,7 @@ public class ExternalJarRunner {
|
||||
}
|
||||
}
|
||||
|
||||
boolean finished = p.waitFor(30, TimeUnit.MINUTES);
|
||||
boolean finished = p.waitFor(TIMEOUT_MINUTES, TimeUnit.MINUTES);
|
||||
if (!finished) {
|
||||
p.destroyForcibly();
|
||||
throw new RuntimeException("jar timeout\n" + out);
|
||||
@@ -66,4 +90,10 @@ public class ExternalJarRunner {
|
||||
log.error("jar execution error. output=\n{}", out, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addArg(List<String> args, String key, String value) {
|
||||
if (value != null && !value.isBlank()) {
|
||||
args.add("--" + key + "=" + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
@@ -45,7 +46,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
|
||||
@Tag(name = "추론관리", description = "추론관리 API")
|
||||
@RequestMapping("/api/inference")
|
||||
@@ -423,30 +423,32 @@ public class InferenceResultApiController {
|
||||
throws IOException {
|
||||
|
||||
String path;
|
||||
String uid;
|
||||
try {
|
||||
path = String.valueOf(inferenceResultService.shpDownloadPath(uuid));
|
||||
Map<String, Object> map = inferenceResultService.shpDownloadPath(uuid);
|
||||
path = String.valueOf(map.get("path"));
|
||||
uid = String.valueOf(map.get("uid"));
|
||||
} catch (CustomApiException e) {
|
||||
// 데이터 없음 등 404
|
||||
return ResponseEntity.status(e.getStatus()).build();
|
||||
}
|
||||
|
||||
Path zipPath = Path.of(path);
|
||||
FileSystemResource resource = new FileSystemResource(zipPath);
|
||||
|
||||
if (!resource.exists() || !resource.isReadable()) {
|
||||
if (!Files.exists(zipPath) || !Files.isReadable(zipPath)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
String filename = zipPath.getFileName().toString();
|
||||
String encodedFilename = UriUtils.encode(filename, StandardCharsets.UTF_8);
|
||||
FileSystemResource resource = new FileSystemResource(zipPath);
|
||||
|
||||
String filename = uid + ".zip";
|
||||
|
||||
long fileSize = Files.size(zipPath);
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(
|
||||
HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=\"" + filename + "\"; filename*=UTF-8''" + encodedFilename)
|
||||
.contentLength(resource.contentLength())
|
||||
.body((Resource) resource);
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
|
||||
.contentLength(fileSize)
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
@Operation(summary = "shp 파일 다운로드 이력", description = "추론관리 분석결과 shp 파일 다운로드 이력")
|
||||
|
||||
@@ -41,6 +41,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -578,11 +579,16 @@ public class InferenceResultService {
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public Path shpDownloadPath(UUID uuid) {
|
||||
public Map<String, Object> shpDownloadPath(UUID uuid) {
|
||||
InferenceLearnDto dto = inferenceResultCoreService.getInferenceUid(uuid);
|
||||
String uid = dto.getUid();
|
||||
Path path = Path.of(datasetDir).resolve(uid).resolve("merge").resolve(uid + ".zip");
|
||||
|
||||
return Path.of(datasetDir).resolve(uid).resolve("merge").resolve(uid + ".zip");
|
||||
Map<String, Object> downloadMap = new HashMap<>();
|
||||
downloadMap.put("uid", uid);
|
||||
downloadMap.put("path", path);
|
||||
|
||||
return downloadMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -187,7 +187,7 @@ public class MapSheetLearnEntity {
|
||||
private int m3FailedJobs = 0;
|
||||
|
||||
@Column(name = "uid", nullable = false)
|
||||
private String uid = UUID.randomUUID().toString().replace("-", "");
|
||||
private String uid = UUID.randomUUID().toString().replace("-", "").toUpperCase();
|
||||
|
||||
public InferenceResultDto.ResultList toDto() {
|
||||
return new InferenceResultDto.ResultList(
|
||||
|
||||
@@ -53,6 +53,9 @@ public class MapSheetInferenceJobService {
|
||||
@Value("${inference.jar-path}")
|
||||
private String jarPath;
|
||||
|
||||
@Value("${file.dataset-dir}")
|
||||
private String datasetDir;
|
||||
|
||||
/** 추론 진행 배치 1분 60_000 */
|
||||
@Scheduled(fixedDelay = 30_000)
|
||||
public void runBatch() {
|
||||
@@ -242,6 +245,10 @@ public class MapSheetInferenceJobService {
|
||||
|
||||
// uid 기준 merge shp, geojson 파일 생성
|
||||
externalJarRunner.run(jarPath, batchId, inferenceId, "");
|
||||
|
||||
// uid 기준 도엽별 shp 파일 geoserver 등록
|
||||
String register = datasetDir + "/" + inferenceId + "/" + "merge" + "/" + inferenceId + ".shp";
|
||||
externalJarRunner.run(jarPath, register, inferenceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user