From 62aa99168019f01655655efc8d5e47359c7249bd Mon Sep 17 00:00:00 2001 From: goulven Date: Mon, 9 Dec 2024 16:07:27 +0100 Subject: [PATCH] Adding sustainalytics company url --- .../scores/SustainalyticsAggregationService.java | 4 ++++ .../commons/model/data/BrandScore.java | 16 +++++++++++++++- .../commons/services/BrandScoreService.java | 5 +++-- .../services/DataFragmentCompletionService.java | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/open4goods/api/services/aggregation/services/batch/scores/SustainalyticsAggregationService.java b/api/src/main/java/org/open4goods/api/services/aggregation/services/batch/scores/SustainalyticsAggregationService.java index d8e8fb0c9..ceac18a03 100644 --- a/api/src/main/java/org/open4goods/api/services/aggregation/services/batch/scores/SustainalyticsAggregationService.java +++ b/api/src/main/java/org/open4goods/api/services/aggregation/services/batch/scores/SustainalyticsAggregationService.java @@ -28,6 +28,8 @@ public class SustainalyticsAggregationService extends AbstractScoreAggregationSe public static final String RISK_LEVEL = "risk-level"; + public static final String COMPANY_URL = "url"; + private BrandService brandService; private BrandScoreService brandScoreService; @@ -74,7 +76,9 @@ public void onProduct(Product data, VerticalConfig vConf) { Map metadatas = new HashMap<>(); metadatas.put(RATING, brandResult.getScoreValue()); metadatas.put(RISK_LEVEL, getRiskLevel(brandResult)); + metadatas.put(COMPANY_URL, brandResult.getUrl()); + s.setMetadatas(metadatas); // Saving in product data.getScores().put(s.getName(),s); } catch (Exception e) { diff --git a/commons/src/main/java/org/open4goods/commons/model/data/BrandScore.java b/commons/src/main/java/org/open4goods/commons/model/data/BrandScore.java index 8c0c52dfd..36a0f9f61 100644 --- a/commons/src/main/java/org/open4goods/commons/model/data/BrandScore.java +++ b/commons/src/main/java/org/open4goods/commons/model/data/BrandScore.java @@ -40,14 +40,18 @@ public class BrandScore { @Field(index = true, store = false, type = FieldType.Keyword) private Set tags = new HashSet<>(); + + @Field(index = true, store = false, type = FieldType.Keyword) + private String url; - public BrandScore(DataSourceProperties datasourceProperties, String brandName, String scoreValue) { + public BrandScore(DataSourceProperties datasourceProperties, String brandName, String scoreValue, String url) { super(); this.datasourceName = datasourceProperties.getName(); this.brandName = brandName.toLowerCase().trim(); this.id=id(datasourceProperties.getName(), brandName); this.lastUpdate = System.currentTimeMillis(); this.scoreValue = scoreValue; + this.url = url; try { Double norm; @@ -146,6 +150,16 @@ public Double getNormalized() { public void setNormalized(Double normalized) { this.normalized = normalized; } + + + public String getUrl() { + return url; + } + + + public void setUrl(String url) { + this.url = url; + } diff --git a/commons/src/main/java/org/open4goods/commons/services/BrandScoreService.java b/commons/src/main/java/org/open4goods/commons/services/BrandScoreService.java index 238287520..319d30803 100644 --- a/commons/src/main/java/org/open4goods/commons/services/BrandScoreService.java +++ b/commons/src/main/java/org/open4goods/commons/services/BrandScoreService.java @@ -41,8 +41,9 @@ public BrandScoreService( BrandScoresRepository brandRepository, String logsFol * @param brand * @param datasourceProperties * @param scoreValue + * @param url */ - public void addBrandScore(String brand, DataSourceProperties datasourceProperties, String scoreValue) { + public void addBrandScore(String brand, DataSourceProperties datasourceProperties, String scoreValue, String url) { if (StringUtils.isEmpty(brand) || StringUtils.isEmpty(scoreValue)) { logger.info("Cannot proceed empty brand or score, skipping"); @@ -58,7 +59,7 @@ public void addBrandScore(String brand, DataSourceProperties datasourcePropertie logger.info("Adding brand score {}:{} for brand {}", datasourceProperties.getName(), scoreValue, brand); - BrandScore brandScore = new BrandScore(datasourceProperties, brand, scoreValue); + BrandScore brandScore = new BrandScore(datasourceProperties, brand, scoreValue, url); diff --git a/crawler/src/main/java/org/open4goods/crawler/services/DataFragmentCompletionService.java b/crawler/src/main/java/org/open4goods/crawler/services/DataFragmentCompletionService.java index a2a4a3e6a..a5771f9fb 100644 --- a/crawler/src/main/java/org/open4goods/crawler/services/DataFragmentCompletionService.java +++ b/crawler/src/main/java/org/open4goods/crawler/services/DataFragmentCompletionService.java @@ -129,7 +129,7 @@ public void complete(final DataFragment o, final String datasourceConfigName, fi Attribute score = o.getAttributes().stream().filter(e-> e.getName().equals("SCORE")).findFirst().orElse(null); if (null != score) { LOGGER.info("Found a brand score for brand {} : {}",o.brand(),score.getRawValue()); - brandService.addBrandScore(o.brand(), datasourceProperties, score.getRawValue()); + brandService.addBrandScore(o.brand(), datasourceProperties, score.getRawValue(), o.affiliatedUrlIfPossible()); } else { LOGGER.warn("Empty brand score found for brand {} ",o.brand()); }