|
|
@ -36,6 +36,29 @@ public class GatesController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private WebClient client; |
|
|
|
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 |
|
|
|
* - template : storage.html |
|
|
@ -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 |
|
|
|
* @param name the name of the file to be deleted |
|
|
|
* @return |
|
|
|
* @return a redirect to the storage page |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("/storage/delete/{name}") |
|
|
|
@GetMapping("/storage/delete/{name}") |
|
|
|
public String deleteFromStorage(@PathVariable String name) { |
|
|
|
public String deleteFromStorage(@PathVariable String name) { |
|
|
|
|
|
|
|
// Prepare the URL for the storage service
|
|
|
|
String filename = name; |
|
|
|
String filename = name; |
|
|
|
String prefix = "http://storage-rs:8282/api/document/"; |
|
|
|
String prefix = "http://storage-rs:8282/api/document/"; |
|
|
|
String postfix = "/delete"; |
|
|
|
String postfix = "/delete"; |
|
|
@ -122,69 +148,68 @@ public class GatesController { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
uri = new URI(prefix + filename + postfix); |
|
|
|
uri = new URI(prefix + filename + postfix); |
|
|
|
|
|
|
|
// Send a DELETE request to the storage service
|
|
|
|
client.method(HttpMethod.DELETE) |
|
|
|
client.method(HttpMethod.DELETE) |
|
|
|
.uri(uri) |
|
|
|
.uri(uri) |
|
|
|
.retrieve() |
|
|
|
.retrieve() |
|
|
|
.bodyToMono(new ParameterizedTypeReference <>(){}) |
|
|
|
.bodyToMono(new ParameterizedTypeReference <>(){}) |
|
|
|
.block(); |
|
|
|
.block(); |
|
|
|
} catch (URISyntaxException e) { |
|
|
|
} 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") |
|
|
|
// Redirect the user to the storage page
|
|
|
|
public String getMethodName(Model model) { |
|
|
|
return "redirect:/storage"; |
|
|
|
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"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Удаление файла из файлового хранилища. |
|
|
|
|
|
|
|
* Удаление сведений о файле из базы данных. |
|
|
|
|
|
|
|
* Направление пользователя на страницу работы со списком файлов. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param id the ID of the file to be deleted |
|
|
|
|
|
|
|
* @return a redirect to the list of files |
|
|
|
|
|
|
|
*/ |
|
|
|
@GetMapping("/document/delete/{id}") |
|
|
|
@GetMapping("/document/delete/{id}") |
|
|
|
public String deleteFromDatabase(@PathVariable String 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) |
|
|
|
Document doc = client.method(HttpMethod.GET) |
|
|
|
.uri("http://resource-service-api:8181/storage-entry/" + id) |
|
|
|
.uri("http://resource-service-api:8181/storage-entry/" + id) |
|
|
|
.retrieve() |
|
|
|
.retrieve() |
|
|
|
.bodyToMono(new ParameterizedTypeReference <Document>(){}) |
|
|
|
.bodyToMono(new ParameterizedTypeReference <Document>(){}) |
|
|
|
.block(); |
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Документ для удаления: " + doc.toString()); |
|
|
|
|
|
|
|
System.out.println("Удаление из хранилища ..."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
System.out.println("Document to be deleted: " + doc.toString()); |
|
|
|
* Удаление файла из хранилища |
|
|
|
System.out.println("Deleting from storage ..."); |
|
|
|
*/ |
|
|
|
|
|
|
|
client.delete() |
|
|
|
|
|
|
|
.uri("http://storage-rs:8282/api/document/delete/" |
|
|
|
|
|
|
|
+ id |
|
|
|
|
|
|
|
+ "." |
|
|
|
|
|
|
|
+ doc.getExtension()) |
|
|
|
|
|
|
|
.retrieve() |
|
|
|
|
|
|
|
.bodyToMono(String.class) |
|
|
|
|
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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() |
|
|
|
client.delete() |
|
|
|
.uri("http://resource-service-api:8181/storage-entry/delete/" + id) |
|
|
|
.uri("http://resource-service-api:8181/storage-entry/delete/" + id) |
|
|
|
.retrieve() |
|
|
|
.retrieve() |
|
|
|
.bodyToMono(String.class) |
|
|
|
.bodyToMono(String.class) |
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
.block(); |
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Файл успешно удален!"); |
|
|
|
System.out.println("File successfully deleted!"); |
|
|
|
|
|
|
|
|
|
|
|
return "redirect:/document/list"; |
|
|
|
return "redirect:/document/list"; |
|
|
|
} |
|
|
|
} |
|
|
@ -202,19 +227,14 @@ public class GatesController { |
|
|
|
Document doc = new Document(); |
|
|
|
Document doc = new Document(); |
|
|
|
doc.setName(file.getOriginalFilename()); |
|
|
|
doc.setName(file.getOriginalFilename()); |
|
|
|
doc.setSize(file.getSize()); |
|
|
|
doc.setSize(file.getSize()); |
|
|
|
/** |
|
|
|
|
|
|
|
* Hfcibhtybt |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Optional<String> ext = Optional.ofNullable(file.getOriginalFilename()) |
|
|
|
Optional<String> ext = Optional.ofNullable(file.getOriginalFilename()) |
|
|
|
.filter(f -> f.contains(".")) |
|
|
|
.filter(f -> f.contains(".")) |
|
|
|
.map(f -> f.substring(file.getOriginalFilename().lastIndexOf(".") + 1)); |
|
|
|
.map(f -> f.substring(file.getOriginalFilename().lastIndexOf(".") + 1)); |
|
|
|
doc.setExtension(ext.get()); |
|
|
|
doc.setExtension(ext.get()); |
|
|
|
doc.setExtension( ext.get()); |
|
|
|
doc.setExtension( ext.get()); |
|
|
|
// doc.setPath();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
// Добавление записи о файле в базу данных
|
|
|
|
* Добавление записи о файле в базу данных |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
doc = client.post() |
|
|
|
doc = client.post() |
|
|
|
.uri("http://resource-service-api:8181/storage-entry/create") |
|
|
|
.uri("http://resource-service-api:8181/storage-entry/create") |
|
|
|
.body(Mono.just(doc), Document.class) |
|
|
|
.body(Mono.just(doc), Document.class) |
|
|
@ -223,9 +243,7 @@ public class GatesController { |
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
.timeout(Duration.ofSeconds(1)) |
|
|
|
.block(); |
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
// Добавление файла в файловое хранилище
|
|
|
|
* Добавление файла в файловое хранилище |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
MultipartBodyBuilder builder = new MultipartBodyBuilder(); |
|
|
|
MultipartBodyBuilder builder = new MultipartBodyBuilder(); |
|
|
|
Boolean ok; |
|
|
|
Boolean ok; |
|
|
|
MultipartFile out = new CustomMultipartFile(file, doc.getId()+"." + doc.getExtension()); |
|
|
|
MultipartFile out = new CustomMultipartFile(file, doc.getId()+"." + doc.getExtension()); |
|
|
|