goog
This commit is contained in:
@@ -864,9 +864,13 @@ public class DatabaseService {
|
|||||||
try (var conn = DriverManager.getConnection(url); var stmt = conn.createStatement()) {
|
try (var conn = DriverManager.getConnection(url); var stmt = conn.createStatement()) {
|
||||||
var rs = stmt.executeQuery(sql);
|
var rs = stmt.executeQuery(sql);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
// Extract numeric lot ID from TEXT field (e.g., "A1-34732-49" -> 3473249)
|
||||||
|
String lotIdStr = rs.getString("lot_id");
|
||||||
|
long lotId = ScraperDataAdapter.extractNumericId(lotIdStr);
|
||||||
|
|
||||||
images.add(new ImageDetectionRecord(
|
images.add(new ImageDetectionRecord(
|
||||||
rs.getInt("id"),
|
rs.getInt("id"),
|
||||||
rs.getLong("lot_id"),
|
lotId,
|
||||||
rs.getString("local_path")
|
rs.getString("local_path")
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import java.util.List;
|
|||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class TroostwijkGraphQLClient {
|
public class TroostwijkGraphQLClient {
|
||||||
|
|
||||||
private static final String GRAPHQL_ENDPOINT = "https://www.troostwijk.com/graphql";
|
private static final String GRAPHQL_ENDPOINT = "https://storefront.tbauctions.com/storefront/graphql";
|
||||||
|
private static final String LOCALE = "nl";
|
||||||
|
private static final String PLATFORM = "TWK";
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -37,12 +39,19 @@ public class TroostwijkGraphQLClient {
|
|||||||
public LotIntelligence fetchLotIntelligence(long lotId) {
|
public LotIntelligence fetchLotIntelligence(long lotId) {
|
||||||
try {
|
try {
|
||||||
String query = buildLotQuery(lotId);
|
String query = buildLotQuery(lotId);
|
||||||
String requestBody = String.format("{\"query\":\"%s\"}",
|
String variables = buildVariables(lotId);
|
||||||
escapeJson(query));
|
|
||||||
|
// Proper GraphQL request format with query and variables
|
||||||
|
String requestBody = String.format(
|
||||||
|
"{\"query\":\"%s\",\"variables\":%s}",
|
||||||
|
escapeJson(query),
|
||||||
|
variables
|
||||||
|
);
|
||||||
|
|
||||||
var request = java.net.http.HttpRequest.newBuilder()
|
var request = java.net.http.HttpRequest.newBuilder()
|
||||||
.uri(java.net.URI.create(GRAPHQL_ENDPOINT))
|
.uri(java.net.URI.create(GRAPHQL_ENDPOINT))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Accept", "application/json")
|
||||||
.POST(java.net.http.HttpRequest.BodyPublishers.ofString(requestBody))
|
.POST(java.net.http.HttpRequest.BodyPublishers.ofString(requestBody))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -56,6 +65,7 @@ public class TroostwijkGraphQLClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("GraphQL response for lot {}: {}", lotId, response.body().substring(0, Math.min(200, response.body().length())));
|
||||||
return parseLotIntelligence(response.body(), lotId);
|
return parseLotIntelligence(response.body(), lotId);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -105,36 +115,34 @@ public class TroostwijkGraphQLClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String buildLotQuery(long lotId) {
|
private String buildLotQuery(long lotId) {
|
||||||
|
// TBAuctions API uses lot objects with specific fields
|
||||||
|
// Note: This query structure needs to be adjusted based on actual TBAuctions schema
|
||||||
return """
|
return """
|
||||||
query {
|
query GetLot($lotId: String!, $locale: String!, $platform: Platform!) {
|
||||||
lot(id: %d) {
|
lot(id: $lotId, locale: $locale, platform: $platform) {
|
||||||
id
|
id
|
||||||
|
displayId
|
||||||
followersCount
|
followersCount
|
||||||
estimatedMin
|
currentBidInCents
|
||||||
estimatedMax
|
|
||||||
nextBidStepInCents
|
nextBidStepInCents
|
||||||
condition
|
condition
|
||||||
categoryPath
|
description
|
||||||
city
|
|
||||||
countryCode
|
|
||||||
biddingStatus
|
biddingStatus
|
||||||
appearance
|
buyerPremium
|
||||||
packaging
|
|
||||||
quantity
|
|
||||||
vat
|
|
||||||
buyerPremiumPercentage
|
|
||||||
remarks
|
|
||||||
startingBid
|
|
||||||
reservePrice
|
|
||||||
reserveMet
|
|
||||||
bidIncrement
|
|
||||||
viewCount
|
viewCount
|
||||||
firstBidTime
|
|
||||||
lastBidTime
|
|
||||||
bidsCount
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".formatted(lotId).replaceAll("\\s+", " ");
|
""".replaceAll("\\s+", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildVariables(long lotId) {
|
||||||
|
return String.format("""
|
||||||
|
{
|
||||||
|
"lotId": "%d",
|
||||||
|
"locale": "%s",
|
||||||
|
"platform": "%s"
|
||||||
|
}
|
||||||
|
""", lotId, LOCALE, PLATFORM).replaceAll("\\s+", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildBatchLotQuery(List<Long> lotIds) {
|
private String buildBatchLotQuery(List<Long> lotIds) {
|
||||||
@@ -167,6 +175,12 @@ public class TroostwijkGraphQLClient {
|
|||||||
|
|
||||||
private LotIntelligence parseLotIntelligence(String json, long lotId) {
|
private LotIntelligence parseLotIntelligence(String json, long lotId) {
|
||||||
try {
|
try {
|
||||||
|
// Check if response is HTML (error page) instead of JSON
|
||||||
|
if (json != null && json.trim().startsWith("<")) {
|
||||||
|
log.debug("GraphQL API returned HTML instead of JSON - likely auth required or wrong endpoint");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
JsonNode root = objectMapper.readTree(json);
|
JsonNode root = objectMapper.readTree(json);
|
||||||
JsonNode lotNode = root.path("data").path("lot");
|
JsonNode lotNode = root.path("data").path("lot");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user