Skip to content

Commit b8cd8f0

Browse files
committed
Remove compiled files and conclude merge with develop
2 parents 8bc73b1 + 2dc8448 commit b8cd8f0

File tree

10 files changed

+184
-2
lines changed

10 files changed

+184
-2
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: ci_outfitlab
2+
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
3+
on:
4+
pull_request:
5+
branches: ["**"]
6+
push:
7+
branches: ["**"]
8+
jobs:
9+
Run-Test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- run: echo "🎉 Esta tarea (job) fue lanzado automaticamente por el evento ${{ github.event_name }}"
13+
- run: echo "🐧 Esta tarea esta corriendo en un servidor ${{ runner.os }} por GitHub!"
14+
- run: echo "🔎 El nombre de la rama es ${{ github.ref }} y tu repositorio es ${{ github.repository }}."
15+
- name: Descargando el codigo
16+
uses: actions/checkout@v3
17+
- run: echo "💡 El repositorio ${{ github.repository }} ha sido clonado."
18+
- run: echo "🖥️ El workflow esta listo para testear el codigo"
19+
- name: Corriendo las pruebas
20+
run: |
21+
mvn clean test
22+
- run: echo "🍏 El estado de la tarea es ${{ job.status }}."

src/main/java/com/outfitlab/project/domain/interfaces/ITrippoService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ public interface ITrippoService {
1212

1313
ByteArrayResource getImageResource(MultipartFile image) throws IOException;
1414

15-
String generateImageToModelTrippo(Map<String, String> imageToken) throws JsonProcessingException; // me va a devolver el image_token
15+
String generateImageToModelTrippo(Map<String, String> imageToken) throws JsonProcessingException; // me va a devolver task_id
1616

1717
boolean validateExtension(String filename);
1818

1919
String getFileExtension(String nombreArchivo);
20+
21+
Map<String, String> checkTaskStatus(String taskId) throws JsonProcessingException, InterruptedException;
22+
23+
Map<String, String> saveFilesFromTask(Map<String, String> taskResponse) throws IOException;
2024
}

src/main/java/com/outfitlab/project/infrastructure/TrippoService.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.outfitlab.project.infrastructure;
22

3+
import org.springframework.http.*;
34
import com.fasterxml.jackson.core.JsonProcessingException;
45
import com.fasterxml.jackson.databind.JsonNode;
56
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -21,6 +22,12 @@
2122
import org.springframework.web.client.RestTemplate;
2223
import org.springframework.web.multipart.MultipartFile;
2324
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.net.URL;
27+
import java.nio.file.Files;
28+
import java.nio.file.Path;
29+
import java.nio.file.Paths;
30+
import java.nio.file.StandardCopyOption;
2431
import java.util.HashMap;
2532
import java.util.Map;
2633

@@ -174,4 +181,73 @@ public String getFileExtension(String nombreArchivo) {
174181
}
175182
return "";
176183
}
184+
185+
@Override
186+
public Map<String, String> checkTaskStatus(String taskId) throws JsonProcessingException, InterruptedException {
187+
Map<String, String> taskStatus = new HashMap<>();
188+
String glbUrl = null;
189+
String webpUrl = null;
190+
191+
for (int i = 0; i < 30; i++) { // acá espero 1 min para ver si ya me generó el glb
192+
Thread.sleep(2000);
193+
194+
HttpHeaders taskHeaders = new HttpHeaders();
195+
taskHeaders.setContentType(MediaType.APPLICATION_JSON);
196+
taskHeaders.setBearerAuth(tripoApiKey);
197+
198+
HttpEntity<Void> entityWithTaskHeaders = new HttpEntity<>(taskHeaders);
199+
ResponseEntity<String> statusResponse = restTemplate.exchange(
200+
taskUrl + "/" + taskId,
201+
HttpMethod.GET,
202+
entityWithTaskHeaders,
203+
String.class);
204+
205+
JsonNode statusJson = mapper.readTree(statusResponse.getBody());
206+
String status = statusJson.path("data").get("status").asText();
207+
208+
if (status.equalsIgnoreCase("success")) {
209+
glbUrl = statusJson.path("data").get("result").get("pbr_model").get("url").asText();
210+
webpUrl = statusJson.path("data").get("result").get("rendered_image").get("url").asText();
211+
taskStatus.put("glbUrl", glbUrl);
212+
taskStatus.put("webpUrl", webpUrl);
213+
taskStatus.put("taskId", taskId);
214+
break;
215+
} else if (status.equalsIgnoreCase("failed")) {
216+
throw new RuntimeException("La tarea falló: " + statusResponse.getBody());
217+
}
218+
}
219+
return taskStatus;
220+
}
221+
222+
@Override
223+
public Map<String, String> saveFilesFromTask(Map<String, String> taskResponse) throws IOException {
224+
// cuando tengamos el AWS, la idea es que estas url las bajemos y enviemos esos archivos a nuestro AWS y luego obtener
225+
// la URL de ESOS archivos recién alojados en nuestro AWS y enviarlas al front así pueden usarlas para mostrarlos.
226+
// (ya que las url de trippo no nos deja usarla en el front)
227+
228+
String imageUrl = taskResponse.get("webpUrl");
229+
String modelUrl = taskResponse.get("glbUrl");
230+
String taskId = taskResponse.get("taskId");
231+
232+
if (imageUrl == null || modelUrl == null || taskId == null) {
233+
throw new IllegalArgumentException("Faltan datos en el mapa");
234+
}
235+
236+
Path resourcesPath = Paths.get("src/main/resources");
237+
Map<String, String> localPaths = new HashMap<>();
238+
239+
Path imagePath = resourcesPath.resolve(taskId + "_image.webp");
240+
try (InputStream in = new URL(imageUrl).openStream()) {
241+
Files.copy(in, imagePath, StandardCopyOption.REPLACE_EXISTING);
242+
}
243+
localPaths.put("image", "resources/" + imagePath.getFileName());
244+
245+
Path modelPath = resourcesPath.resolve(taskId + "_3d.glb");
246+
try (InputStream in = new URL(modelUrl).openStream()) {
247+
Files.copy(in, modelPath, StandardCopyOption.REPLACE_EXISTING);
248+
}
249+
localPaths.put("glb", "resources/" + modelPath.getFileName());
250+
251+
return localPaths;
252+
}
177253
}

src/test/java/com/outfitlab/project/infrastructure/TrippoServiceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.io.IOException;
1717
import java.util.HashMap;
1818
import java.util.Map;
19-
import java.util.Optional;
2019

2120
import static org.junit.jupiter.api.Assertions.*;
2221
import static org.mockito.Mockito.*;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

target/surefire-reports/TEST-com.outfitlab.project.infrastructure.TrippoServiceTest.xml

Lines changed: 77 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-------------------------------------------------------------------------------
2+
Test set: com.outfitlab.project.infrastructure.TrippoServiceTest
3+
-------------------------------------------------------------------------------
4+
Tests run: 15, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.571 s -- in com.outfitlab.project.infrastructure.TrippoServiceTest

0 commit comments

Comments
 (0)