|
|
|
@ -36,6 +36,29 @@ public class GatesController {
@@ -36,6 +36,29 @@ public class GatesController {
|
|
|
|
|
@Autowired |
|
|
|
|
private WebClient client; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get list of documents from the resource service API and add to model |
|
|
|
|
* - endpoint: /document/list |
|
|
|
|
* |
|
|
|
|
* @param model the model to add the documents to |
|
|
|
|
* @return the view name "documents" |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/document/list") |
|
|
|
|
public String getMethodName(Model model) { |
|
|
|
|
// Call the resource service API to get the list of documents
|
|
|
|
|
List<Document> docs = client.method(HttpMethod.GET) |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/list") |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(new ParameterizedTypeReference <List<Document>>(){}) |
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
// Add the list of documents to the model
|
|
|
|
|
model.addAttribute("documents", docs); |
|
|
|
|
|
|
|
|
|
// Return the view name "documents"
|
|
|
|
|
return "documents"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Получение списка файлов с сервера и доступа к инструментам извлечения данных |
|
|
|
|
* - template : storage.html |
|
|
|
@ -105,16 +128,19 @@ public class GatesController {
@@ -105,16 +128,19 @@ public class GatesController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Удаление файла из хранилища |
|
|
|
|
* и возврат пользователю страницы работы с файлами |
|
|
|
|
* !!! Добавить удаление записи из базы |
|
|
|
|
* !!! Обернуть в транзакцию |
|
|
|
|
* Deletes a file from the storage and redirects the user to the storage page. |
|
|
|
|
* TODO: Add deletion of the record from the database |
|
|
|
|
* TODO: Wrap the operation in a transaction |
|
|
|
|
* не корректно дублирует метод удаления файла по id |
|
|
|
|
* - раняя реализация (устарела) |
|
|
|
|
* - сохранилась в классе для поддержания работоспособности старого кода |
|
|
|
|
* |
|
|
|
|
* @param name |
|
|
|
|
* @return |
|
|
|
|
* @param name the name of the file to be deleted |
|
|
|
|
* @return a redirect to the storage page |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/storage/delete/{name}") |
|
|
|
|
public String deleteFromStorage(@PathVariable String name) { |
|
|
|
|
// Prepare the URL for the storage service
|
|
|
|
|
String filename = name; |
|
|
|
|
String prefix = "http://storage-rs:8282/api/document/"; |
|
|
|
|
String postfix = "/delete"; |
|
|
|
@ -122,69 +148,68 @@ public class GatesController {
@@ -122,69 +148,68 @@ public class GatesController {
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
uri = new URI(prefix + filename + postfix); |
|
|
|
|
// Send a DELETE request to the storage service
|
|
|
|
|
client.method(HttpMethod.DELETE) |
|
|
|
|
.uri(uri) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(new ParameterizedTypeReference <>(){}) |
|
|
|
|
.block(); |
|
|
|
|
} catch (URISyntaxException e) { |
|
|
|
|
System.out.println("Не верный URI: " + e.getMessage()); |
|
|
|
|
// Print an error message if the URI is invalid
|
|
|
|
|
System.out.println("Invalid URI: " + e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return "redirect:/storage"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@GetMapping("/document/list") |
|
|
|
|
public String getMethodName(Model model) { |
|
|
|
|
List<Document> docs = client.method(HttpMethod.GET) |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/list") |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(new ParameterizedTypeReference <List<Document>>(){}) |
|
|
|
|
.block(); |
|
|
|
|
model.addAttribute("documents", docs); |
|
|
|
|
return "documents"; |
|
|
|
|
// Redirect the user to the storage page
|
|
|
|
|
return "redirect:/storage"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Удаление файла из файлового хранилища. |
|
|
|
|
* Удаление сведений о файле из базы данных. |
|
|
|
|
* Направление пользователя на страницу работы со списком файлов. |
|
|
|
|
* |
|
|
|
|
* @param id the ID of the file to be deleted |
|
|
|
|
* @return a redirect to the list of files |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/document/delete/{id}") |
|
|
|
|
public String deleteFromDatabase(@PathVariable String id) { |
|
|
|
|
System.out.println("gates# получение сведений о файле ... " + id); |
|
|
|
|
/** |
|
|
|
|
* Получеие сведений о файле из базы |
|
|
|
|
*/ |
|
|
|
|
// Get the details of the file from the database
|
|
|
|
|
System.out.println("gates# Getting details of the file ... " + id); |
|
|
|
|
Document doc = client.method(HttpMethod.GET) |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/" + id) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(new ParameterizedTypeReference <Document>(){}) |
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
System.out.println("Документ для удаления: " + doc.toString()); |
|
|
|
|
System.out.println("Удаление из хранилища ..."); |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/" + id) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(new ParameterizedTypeReference <Document>(){}) |
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Удаление файла из хранилища |
|
|
|
|
*/ |
|
|
|
|
client.delete() |
|
|
|
|
.uri("http://storage-rs:8282/api/document/delete/" |
|
|
|
|
+ id |
|
|
|
|
+ "." |
|
|
|
|
+ doc.getExtension()) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(String.class) |
|
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
|
.block(); |
|
|
|
|
System.out.println("Document to be deleted: " + doc.toString()); |
|
|
|
|
System.out.println("Deleting from storage ..."); |
|
|
|
|
|
|
|
|
|
// Delete the file from the storage
|
|
|
|
|
String filename = id + "." + doc.getExtension(); |
|
|
|
|
String prefix = "http://storage-rs:8282/api/document/"; |
|
|
|
|
String postfix = "/delete"; |
|
|
|
|
URI uri; |
|
|
|
|
try { |
|
|
|
|
uri = new URI(prefix + filename + postfix); |
|
|
|
|
client.method(HttpMethod.DELETE) |
|
|
|
|
.uri(uri) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(new ParameterizedTypeReference <>(){}) |
|
|
|
|
.block(); |
|
|
|
|
} catch (URISyntaxException e) { |
|
|
|
|
System.out.println("Invalid URI: " + e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
System.out.println("Удаление из базы ..."); |
|
|
|
|
/** |
|
|
|
|
* Удаление записи о файле из базы |
|
|
|
|
*/ |
|
|
|
|
System.out.println("Deleting from the database ..."); |
|
|
|
|
// Delete the entry for the file from the database
|
|
|
|
|
client.delete() |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/delete/" + id) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(String.class) |
|
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
|
.block(); |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/delete/" + id) |
|
|
|
|
.retrieve() |
|
|
|
|
.bodyToMono(String.class) |
|
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
System.out.println("Файл успешно удален!"); |
|
|
|
|
System.out.println("File successfully deleted!"); |
|
|
|
|
|
|
|
|
|
return "redirect:/document/list"; |
|
|
|
|
} |
|
|
|
@ -202,19 +227,14 @@ public class GatesController {
@@ -202,19 +227,14 @@ public class GatesController {
|
|
|
|
|
Document doc = new Document(); |
|
|
|
|
doc.setName(file.getOriginalFilename()); |
|
|
|
|
doc.setSize(file.getSize()); |
|
|
|
|
/** |
|
|
|
|
* Hfcibhtybt |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
Optional<String> ext = Optional.ofNullable(file.getOriginalFilename()) |
|
|
|
|
.filter(f -> f.contains(".")) |
|
|
|
|
.map(f -> f.substring(file.getOriginalFilename().lastIndexOf(".") + 1)); |
|
|
|
|
doc.setExtension(ext.get()); |
|
|
|
|
doc.setExtension( ext.get()); |
|
|
|
|
// doc.setPath();
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Добавление записи о файле в базу данных |
|
|
|
|
*/ |
|
|
|
|
// Добавление записи о файле в базу данных
|
|
|
|
|
doc = client.post() |
|
|
|
|
.uri("http://resource-service-api:8181/storage-entry/create") |
|
|
|
|
.body(Mono.just(doc), Document.class) |
|
|
|
@ -223,9 +243,7 @@ public class GatesController {
@@ -223,9 +243,7 @@ public class GatesController {
|
|
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Добавление файла в файловое хранилище |
|
|
|
|
*/ |
|
|
|
|
// Добавление файла в файловое хранилище
|
|
|
|
|
MultipartBodyBuilder builder = new MultipartBodyBuilder(); |
|
|
|
|
Boolean ok; |
|
|
|
|
MultipartFile out = new CustomMultipartFile(file, doc.getId()+"." + doc.getExtension()); |
|
|
|
|