|
|
@@ -5,6 +5,9 @@ import java.net.http.HttpClient;
|
|
|
import java.net.http.HttpRequest;
|
|
|
import java.net.http.HttpResponse;
|
|
|
|
|
|
+import javax.print.Doc;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
@@ -15,6 +18,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
import es.uv.saic.dto.CategoriaDTO;
|
|
|
import es.uv.saic.dto.DocumentTmpDTO;
|
|
|
+import es.uv.saic.feign.DocumentClient;
|
|
|
import es.uv.saic.domain.Document;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
@@ -28,6 +32,9 @@ public class DocumentController {
|
|
|
private final HttpClient httpClient = HttpClient.newHttpClient();
|
|
|
private final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DocumentClient dc;
|
|
|
+
|
|
|
/*
|
|
|
* endpoint para save
|
|
|
*/
|
|
|
@@ -55,16 +62,10 @@ public class DocumentController {
|
|
|
@PostMapping("/findByCategoriaOrgan")
|
|
|
public ResponseEntity<?> findByCategoriaOrgan(@RequestBody CategoriaDTO categoria) {
|
|
|
try {
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(uriDocs + "/findByCategoriaOrgan"))
|
|
|
- .header("Content-Type", "application/json")
|
|
|
- .POST(HttpRequest.BodyPublishers.ofString(mapper.writeValueAsString(categoria)))
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- return ResponseEntity.status(response.statusCode()).body(response.body());
|
|
|
+ ResponseEntity<?> doc = dc.findByCategoriaOrgan(categoria);
|
|
|
+ return ResponseEntity.ok(doc);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ e.printStackTrace();
|
|
|
return ResponseEntity.badRequest().body("Error comunicando con servicio de documentos: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@@ -75,13 +76,8 @@ public class DocumentController {
|
|
|
@GetMapping("/document/{idDocument}")
|
|
|
public ResponseEntity<?> findByID(@PathVariable Integer idDocument) {
|
|
|
try {
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
- .uri(URI.create(uriDocs + "/document/" + idDocument))
|
|
|
- .GET()
|
|
|
- .build();
|
|
|
-
|
|
|
- HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
|
|
- return ResponseEntity.status(response.statusCode()).body(response.body());
|
|
|
+ ResponseEntity<?> doc = dc.findByID(idDocument);
|
|
|
+ return ResponseEntity.ok(doc);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return ResponseEntity.badRequest().body("Error comunicando con servicio de documentos: " + e.getMessage());
|