Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warehouse-paging-test #121

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@SpringBootApplication
public class WarehouseApplication {

public static void main(String[] args) {
public static void main(String[] args) {

SpringApplication.run(WarehouseApplication.class, args);
}
SpringApplication.run(WarehouseApplication.class, args);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class DownloadController {
DownloadStatusMapper downloadStatusMapper;

String userDirectory = new File("").getAbsolutePath();
final String prefix = userDirectory + "/src/main/resources/report/";
//final String prefix = userDirectory + "/src/main/resources/report/";
final String prefix = userDirectory + "/src/main/resources/";

@GetMapping("/list")
public String list(Map<String, Object> map, @RequestParam(value="pageNo", required=false, defaultValue="1") String pageNoStr) {
Expand Down Expand Up @@ -77,6 +78,7 @@ public String createDownload() {
map.put("age", 17);
// save file to local // TODO : save it to remote file system (e.g. S3)
Boolean result = fileUtil.writeJsonFile(map, prefix + fileName);
//Boolean result = fileUtil.writeJsonFile(map, fileName);
if (result) {
DownloadStatus downloadStatus = new DownloadStatus();
downloadStatus.setStatus("completed");
Expand All @@ -97,10 +99,16 @@ public ResponseEntity<Resource> downloadFile(String url) throws IOException {

log.info(">>> (ResponseEntity<Resource> downloadFile) url = " + url);
//List<DownloadStatus> downloadStatusList = downloadStatusMapper.getAllDownloadStatus();
//String downloadUrl = "/report/" + downloadStatusList.get(0).getDownloadUrl();
String downloadUrl = "/report/" + url;
log.info("downloadUrl = " + downloadUrl);
Resource resource = new ClassPathResource(downloadUrl);
String downloadUrl = url;
log.info(">>> downloadUrl = " + downloadUrl);

// TODO : fix why can't read file from downloadUrl
//ClassPathResource resource = new ClassPathResource(String.valueOf(downloadUrl));
ClassPathResource resource = new ClassPathResource("demo_report.json");
log.info(resource.getPath());
log.info(String.valueOf(resource.exists()));
log.info(String.valueOf(resource.getURL()));

HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=%s".format("test.json"));

Expand Down
1 change: 1 addition & 0 deletions springWarehouse/src/main/resources/demo_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"king","age":17}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"king","age":17}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.yen.springWarehouse.util.DateTimeUtils;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.text.SimpleDateFormat;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -21,4 +24,21 @@ public void testPrepareDownloadFile(){
System.out.println(dateTimeUtils.getCurrentDateYYYYMMDDHHMMSS());
}

@Test
public void testGetResourcePath() throws IOException {

ClassPathResource r1 = new ClassPathResource("application.properties");
System.out.println(r1.getPath());
System.out.println(r1.exists());
System.out.println(r1.getURL());

//ClassPathResource r2 = new ClassPathResource("/report/20231123-16-16-09_report.json");
ClassPathResource r2 = new ClassPathResource("20231123-16-52-30_report.json");
System.out.println(r2.getPath());
System.out.println(r2.exists());
System.out.println(r2.getURL());


}

}