Skip to content

Commit 96208d0

Browse files
committed
Removes FlareSolverr integration
Removes the FlareSolverr integration from the application. The application now directly fetches data. This simplifies the code and reduces external dependencies.
1 parent 824af9c commit 96208d0

File tree

3 files changed

+4
-49
lines changed

3 files changed

+4
-49
lines changed

docker-compose.prod.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ services:
1212
- SPRING_DATA_MONGODB_DATABASE=${MONGO_DATABASE}
1313
- SPRING_DATA_MONGODB_USERNAME=${MONGO_USERNAME}
1414
- SPRING_DATA_MONGODB_PASSWORD=${MONGO_PASSWORD}
15-
- FLARESOLVERR_URL=${FLARE_URL}
1615
restart: unless-stopped

src/main/java/com/dmware/api_onibusbh/services/APIService.java

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
import java.util.List;
99
import java.util.Map;
1010

11-
import com.mongodb.lang.Nullable;
1211
import org.springframework.beans.factory.annotation.Value;
13-
import org.springframework.http.HttpHeaders;
14-
import org.springframework.http.MediaType;
1512
import org.springframework.stereotype.Service;
16-
import org.springframework.web.reactive.function.client.WebClient;
1713
import org.springframework.web.reactive.function.client.WebClientResponseException;
1814

1915
import com.dmware.api_onibusbh.config.WebClientConfig;
@@ -25,7 +21,6 @@
2521
import com.fasterxml.jackson.databind.ObjectMapper;
2622
import reactor.core.publisher.Flux;
2723
import reactor.core.publisher.Mono;
28-
import reactor.util.function.Tuple2;
2924

3025
@Service
3126
public class APIService {
@@ -34,9 +29,6 @@ public class APIService {
3429
private String BASE_PATH;
3530
@Value("${FILE_NAME}")
3631
private String FILE_NAME;
37-
@Value("${FLARESOLVERR_URL:#{null}}")
38-
@Nullable
39-
private String flareSolverrUrl;
4032

4133
private final WebClientConfig webClientConfig;
4234
private final ObjectMapper objectMapper;
@@ -95,15 +87,8 @@ public List<LinhaDTO> getLinhasAPIBH() {
9587
}
9688

9789
public void getOnibusCoordenadaBH() throws IOException {
98-
List<String> responses;
99-
100-
if (flareSolverrUrl != null && !flareSolverrUrl.isBlank()) {
101-
System.out.printf("Usando FlareSolverr em: %s%n", flareSolverrUrl);
102-
responses = fetchCoordenadasViaFlareSolverr();
103-
} else {
104-
System.out.printf("Acessando diretamente sem FlareSolverr.%n");
105-
responses = fetchCoordenadasDirectly();
106-
}
90+
System.out.printf("Acessando diretamente.%n");
91+
List<String> responses = fetchCoordenadasDirectly();
10792

10893
if (responses == null || responses.size() < 2) {
10994
throw new IllegalStateException("Não foi possível obter resposta de um ou mais endpoints.");
@@ -126,34 +111,6 @@ private List<String> fetchCoordenadasDirectly() {
126111
return Flux.merge(monoParamD, monoParamSD).collectList().block();
127112
}
128113

129-
private List<String> fetchCoordenadasViaFlareSolverr() throws JsonProcessingException {
130-
WebClient flareSolverrClient = WebClient.builder()
131-
.baseUrl(flareSolverrUrl + "/v1")
132-
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
133-
.build();
134-
135-
String cmdParamD = "{\"cmd\": \"request.get\", \"url\": \"https://temporeal.pbh.gov.br/?param=D\", \"maxTimeout\": 60000}";
136-
String cmdParamSD = "{\"cmd\": \"request.get\", \"url\": \"https://temporeal.pbh.gov.br/?param=SD\", \"maxTimeout\": 60000}";
137-
138-
Mono<String> monoResponseD = flareSolverrClient.post().bodyValue(cmdParamD).retrieve().bodyToMono(String.class);
139-
Mono<String> monoResponseSD = flareSolverrClient.post().bodyValue(cmdParamSD).retrieve().bodyToMono(String.class);
140-
141-
List<String> flareSolverrResponses = Flux.merge(monoResponseD, monoResponseSD).collectList().block();
142-
143-
if (flareSolverrResponses == null || flareSolverrResponses.size() < 2) {
144-
return null;
145-
}
146-
147-
// Extrai a resposta real do JSON do FlareSolverr
148-
JsonNode rootNodeD = objectMapper.readTree(flareSolverrResponses.get(0));
149-
String jsonD = rootNodeD.path("solution").path("response").asText();
150-
151-
JsonNode rootNodeSD = objectMapper.readTree(flareSolverrResponses.get(1));
152-
String jsonSD = rootNodeSD.path("solution").path("response").asText();
153-
154-
return List.of(jsonD, jsonSD);
155-
}
156-
157114
private void processAndSaveCoordenadas(List<String> responses) throws IOException {
158115
String jsonD = responses.get(0);
159116
String jsonSD = responses.get(1);
@@ -181,4 +138,4 @@ private void processAndSaveCoordenadas(List<String> responses) throws IOExceptio
181138
throw new RuntimeException("Erro ao processar o JSON das coordenadas.", e);
182139
}
183140
}
184-
}
141+
}

src/main/resources/application-prod.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ spring.data.mongodb.host=${MONGO_HOST}
33
spring.data.mongodb.port=${MONGO_PORT}
44
spring.data.mongodb.database=${MONGO_DATABASE}
55
spring.data.mongodb.username=${MONGO_USERNAME}
6-
spring.data.mongodb.password=${MONGO_PASSWORD}
7-
FLARESOLVERR_URL=${FLARE_URL}
6+
spring.data.mongodb.password=${MONGO_PASSWORD}

0 commit comments

Comments
 (0)